+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    04-23-2004
    Location
    Washington State
    MS-Off Ver
    Whatever the government has on my computer
    Posts
    41

    Intermittent Runtime Error when inserting picture

    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...

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    2,815

    Re: Intermittent Runtime Error when inserting picture

    Try...

    Code:
    Set objImg = ActiveSheet.DrawingObjects(ActiveSheet.DrawingObjects.Count)
    ...just in case there are Shapes which are not being counted as DrawingObjects.
    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.

  3. #3
    Registered User
    Join Date
    04-23-2004
    Location
    Washington State
    MS-Off Ver
    Whatever the government has on my computer
    Posts
    41

    Re: Intermittent Runtime Error when inserting picture

    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...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0