Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Compile error with excel 2007 (https://www.askmehelpdesk.com/showthread.php?t=300700)

  • Jan 7, 2009, 09:48 PM
    natanab
    Compile error with excel 2007
    I have written a very basic Macros code to retrieve a photo off my server. I want it to run this macro when a person has selected a certain item off a drop down list. The problem I am having is that when I try and run the macro manually or when the workbook opens I get a an error message that reads "Compile Error: Invalid outside procedure". I click "Okay"
    And it show a portion of the code from line

    -Range("G48").Select- is highlighted.

    The part "G48" is highlighted. Can't figure out why. I recorded the Macro in excel 2003 because excel 200 doesn't let you record macros that insert pictures. It is supposed to work according to Microsoft if you record the code in 2003 and copy it to 2007. I'm looking for a more educated person to answer this please.

    Here is the whole macro code:

    ' Solar_world_175 Macro
    '

    '
    Range("G48").Select
    ActiveSheet.Pictures.Insert( _
    "\\Pele\work\Pictures\Solar Proposal Pictures\solar world panel
    2008.bmp"). _
    Select
    End Sub


    Very basic yet ift won't work.

    Thanks in advance.
  • Jan 8, 2009, 12:06 AM
    JBeaucaire

    You seem to be selecting the cell, but don't actually tell Excel to insert the picture here. You also have select after the insert, this is wrong.

    You rarely have to select a range in VBA, doing so only slows the code.

    Try:

    Code:

    ActiveSheet.Range("G48").Pictures.Insert( _
      "\\Pele\work\Pictures\Solar Proposal Pictures\solar world panel 2008.bmp")

    Edit that path to the picture if I transposed it incorrectly.
  • Jan 8, 2009, 06:24 AM
    JBeaucaire

    A colleague suggested the following:
    ==============
    xl2007 unlike previous version does not insert the picture in relation to the active cell when using code.
    You need to insert and then position.


    Code:

        With ActiveSheet.Pictures.Insert("\\Pele\work\Pictures\Solar Proposal Pictures\solar world panel 2008.bmp")
            .Left = Range("G48").Left
            .Top = Range("G48").Top
        End With


  • All times are GMT -7. The time now is 06:50 PM.