Private Sub CommandButton1_Click()
Dim myImage As Variant, defaultFolderPath As String
defaultFolderPath = "[COLOR=#ff0000]C:\Folder\subfolder[/COLOR]"
[I][COLOR=#000080]'hide userform[/COLOR][/I]
Me.Hide
[I][COLOR=#000080]'where is image placed?[/COLOR][/I]
Sheets("[COLOR=#ff0000]SheetName[/COLOR]").Activate
Application.InputBox("Select Cell with mouse and click ok", "Insert Image", , , , , , 8).Select
[I][COLOR=#000080]'which image?[/COLOR][/I]
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = defaultFolderPath & "\"
.Title = "Choose File"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
myImage = .SelectedItems(1)
End With
[I][COLOR=#000080]'insert chosen image in selected cell and show userform[/COLOR][/I]
ActiveSheet.Pictures.Insert (myImage)
Me.Show
End Sub
Try this
Amend default folder path and sheet name
Code:Private Sub CommandButton1_Click() Dim myImage As Variant, defaultFolderPath As String defaultFolderPath = "[COLOR=#ff0000]C:\Folder\subfolder[/COLOR]" [I][COLOR=#000080]'hide userform[/COLOR][/I] Me.Hide [I][COLOR=#000080]'where is image placed?[/COLOR][/I] Sheets("[COLOR=#ff0000]SheetName[/COLOR]").Activate Application.InputBox("Select Cell with mouse and click ok", "Insert Image", , , , , , 8).Select [I][COLOR=#000080]'which image?[/COLOR][/I] With Application.FileDialog(msoFileDialogOpen) .InitialFileName = defaultFolderPath & "\" .Title = "Choose File" .AllowMultiSelect = False If .Show <> -1 Then Exit Sub myImage = .SelectedItems(1) End With [I][COLOR=#000080]'insert chosen image in selected cell and show userform[/COLOR][/I] ActiveSheet.Pictures.Insert (myImage) Me.Show End Sub
Private Sub CommandButton1_Click()
Dim myImage As Variant, defaultFolderPath As String
defaultFolderPath = "C:\TestArea\pdf"
'hide userform
Me.Hide
'where is image placed?
Sheets("SheetName").Activate
Application.InputBox("Select Cell with mouse and click ok", "Insert Image", , , , , , 8).Select
'which image?
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = defaultFolderPath & "\"
.Title = "Choose File"
.AllowMultiSelect = False
If .Show <> -1 Then[COLOR=#ff0000] GoTo TheEnd:[/COLOR]
myImage = .SelectedItems(1)
End With
'insert chosen image in selected cell and show userform
ActiveSheet.Pictures.Insert (myImage)
[COLOR=#ff0000]TheEnd:[/COLOR]
Me.Show
End Sub