I get error Run-time error "91"
Object Variable or With Block variable not set
Any help pls? My code below:
Private Sub CommandButton1_Click()
Dim myPicture As String, myRange As Range 'set of variables for the image and a selected cell
'defining image formats for import
myPicture = Application.GetOpenFilename _
("Pictures (.gif; .jpg; .bmp; .tif),.gif; .jpg; .bmp; .tif", _
, "Choose image for insert")
Range("A15").Select
'Set myRange = Application.InputBox(A15) 'message to select the destination cell - option
InsertAndSizePic myRange, myPicture 'calling the procedure for resizing images
End Sub
Sub InsertAndSizePic(Target As Range, PicPath As String)
Dim p As Picture
Application.ScreenUpdating = False
Set p = ActiveSheet.Pictures.Insert(PicPath)
If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
With Target
p.Top = .Top
p.Left = .Left
p.Width = .Width
p.Height = .Height
End With
End Sub
Object Variable or With Block variable not set
Any help pls? My code below:
Private Sub CommandButton1_Click()
Dim myPicture As String, myRange As Range 'set of variables for the image and a selected cell
'defining image formats for import
myPicture = Application.GetOpenFilename _
("Pictures (.gif; .jpg; .bmp; .tif),.gif; .jpg; .bmp; .tif", _
, "Choose image for insert")
Range("A15").Select
'Set myRange = Application.InputBox(A15) 'message to select the destination cell - option
InsertAndSizePic myRange, myPicture 'calling the procedure for resizing images
End Sub
Sub InsertAndSizePic(Target As Range, PicPath As String)
Dim p As Picture
Application.ScreenUpdating = False
Set p = ActiveSheet.Pictures.Insert(PicPath)
If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
With Target
p.Top = .Top
p.Left = .Left
p.Width = .Width
p.Height = .Height
End With
End Sub