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
Code: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
Last edited by vamosj; 05-05-2009 at 02:35 AM.
Janos S. Vamos FC1 (X-DS)
US Navy
Xerox Tech
Advance Combat Direction System Tech
DD973 Computer/Peripheral Tech
Snap II Tech
MWR Leading Petty Officer
Corrections Officer
A man with many hats
There are only 10 kind of people in this world. Those that understand Binary and those that don't...
Try...
...just in case there are Shapes which are not being counted as DrawingObjects.Code:Set objImg = ActiveSheet.DrawingObjects(ActiveSheet.DrawingObjects.Count)
Martin
Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.
If my solution has saved you time and/or money, please consider donating to Cancer Research UK.
Thanks,
I will have to run it over a few times. Probably have some of my coworkers try it out also before I make my determination that it is fixed. As I said, this pops up on occasion (usually when I'm showing one of my bosses on how it works)...
**** Edit **** After a few days of testing this seems to have fixed the problem. Many thanks for your input mrice.
Last edited by vamosj; 05-05-2009 at 02:36 AM. Reason: Update Solved
Janos S. Vamos FC1 (X-DS)
US Navy
Xerox Tech
Advance Combat Direction System Tech
DD973 Computer/Peripheral Tech
Snap II Tech
MWR Leading Petty Officer
Corrections Officer
A man with many hats
There are only 10 kind of people in this world. Those that understand Binary and those that don't...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks