Reputation:
This Macro works perfectly when it's on a fresh(empty) workbook but when I try to add it to an existing workbook it throws up the titled error.
It shows img as empty when I break and hover, and I'm not sure why!
Thanks in advance.
Sub Insert_Image()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select an image file"
.Filters.Clear
.Filters.Add "JPG", "*.JPG"
.Filters.Add "JPEG File Interchange Format", "*.JPEG"
.Filters.Add "Graphics Interchange Format", "*.GIF"
.Filters.Add "Portable Network Graphics", "*.PNG"
.Filters.Add "Tag Image File Format", "*.TIFF"
.Filters.Add "All Pictures", "*.*"
If .Show = -1 Then
Dim img As Object
Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))
img.Left = 50
img.Top = 150
img.Width = 150
img.Height = 150
End If
End With
End Sub
Upvotes: 0
Views: 1607
Reputation:
Figured it out, the worksheet cannot be protected.
Unprotect, fiddle with whatever, protect.
Works as expected.
Upvotes: 1