PDA

View Full Version : [SOLVED] Insert picture into image control



YasserKhalil
09-26-2017, 06:03 AM
Hello everyone
I need to insert a picture using filedialog

Private Sub CommandButton1_Click() Dim dlg As FileDialog


Set dlg = Application.FileDialog(msoFileDialogOpen)
dlg.InitialFileName = "D:\Alwared\"

If dlg.Show Then
Me.Image1.Picture = LoadPicture(dlg)
Else
MsgBox "File Not Selected", vbExclamation
End If

Set dlg = Nothing
End Sub

I got an error when trying to insert the picture
Any idea?

mana
09-26-2017, 06:19 AM
Me.Image1.Picture = LoadPicture(dlg.SelectedItems(1))

YasserKhalil
09-26-2017, 06:50 AM
Thank you very much.. It is working
How can fit the picture inserted in the image control?

mana
09-26-2017, 07:00 AM
PictureSizeMode (https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/picturesizemode-property)

YasserKhalil
09-26-2017, 07:06 AM
Thank you very much for great help

YasserKhalil
09-26-2017, 07:09 AM
Just last point : How to insert the picture from the userform to worksheet in cell G10 for example?

YasserKhalil
09-26-2017, 07:13 AM
I found this code but it doesn't specify the specific cell or target cell where I would like to insert?

mana
09-26-2017, 08:05 AM
If dlg.Show Then
Set ws = Sheets(1)
L = ws.Range("g10").Left
T = ws.Range("g10").Top

With ws.Shapes.AddPicture( _
Filename:=dlg.SelectedItems(1), _
LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=L, _
Top:=T, _
Width:=0, _
Height:=0)

.ScaleHeight 1, msoTrue
.ScaleWidth 1, msoTrue
End With
Else
MsgBox "File Not Selected", vbExclamation
End If

YasserKhalil
09-26-2017, 11:41 AM
Thank you very much for great support and help
Best Regards