I'm having difficulty nailing this one down as it does it on occasion and I can't figure out the key to it. It may do it on startup or it may do it after a few other macro's are ran. Can anyone see any problems within this code that might cause such an issue?
The error I am getting (highlighted in red) is that it cannot view the object properties. So the picture is put in, but it's emplacement cannot be set and the picture cannot be renamed (which must occur for other macros to see it).
- Pages are not protected
- The only self automated macro is on workbook open, and it only resizes to view the area depending on the persons resolution.
- Microsoft Excel 2003
![]()
Sub insertpictureonclick() Dim Emplacement As Range Dim objImg As Object Dim myPicture As Variant On Error Resume Next ActiveSheet.Shapes("Picture 1").Delete ActiveSheet.Shapes("Picture 2").Delete ActiveSheet.Shapes("Picture 3").Delete ActiveSheet.Shapes("Picture 4").Delete ActiveSheet.Shapes("Picture 5").Delete myPicture = Application.GetOpenFilename _ ("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _ , "Select Picture to Import") If myPicture = False Then Exit Sub ActiveSheet.Pictures.Insert (myPicture) Set Emplacement = Range("M2:S29") Set objImg = ActiveSheet.DrawingObjects(ActiveSheet.Shapes.Count) ActiveSheet.DrawingObjects(ActiveSheet.Shapes.Count).Select Selection.Name = "Picture 1" With objImg.ShapeRange .LockAspectRatio = msoFalse .Left = Emplacement.Left .Top = Emplacement.Top .Height = Emplacement.Height .Width = Emplacement.Width End With End Sub
Bookmarks