Ask Experts Questions for FREE Help !
Ask
    natanab's Avatar
    natanab Posts: 2, Reputation: 1
    New Member
     
    #1

    Jan 7, 2009, 09:48 PM
    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.
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Jan 8, 2009, 12:06 AM

    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.
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #3

    Jan 8, 2009, 06:24 AM

    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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Connect two different sheet in Excel 2007 [ 6 Answers ]

I am using Excel 2007. I want to put the calculation part or the detail figure in one sheet. And I want to put the relating pi chart or some other graphical representation on some other sheet. How I would relate these two sheets so that when I make any changes in the figure in the first sheet...

Excel 2007 to have excel 2003 look? [ 6 Answers ]

Hey I have Microsoft Excel 2007, from my course at college I have been given instructions to do a task. However these instructions are for excel 2003. How do I change my excel 07 to look like excel 03 so that it is easier. I know there is a way, help greatly appreicated thanks.

Format Cells in Excel 2007 [ 4 Answers ]

Is there a way in Excel to automate adding hyphens in a specific position in a column of numbers (like a mac address list) For example: 0021e96c4183 00-21-e9-6c-41-83 HOWEVER When I use this method Home tab, Cell group, click on Format On Number tab from the Format Cells dialog screen I'd...

Memory Usage in Excel 2007 [ 2 Answers ]

I am trying to do simple operations (multiplication, division, cut, copy, paste, insert columns, etc.) in a large database in excel 2007 (500,000 rows x 60 columns). However, my XP machine (1gb) gives an out of memory error - I have stopped all unnecessary programs but this message keeps...

Activating Macro in Excel 2007 [ 1 Answers ]

When transferred my files from an old computer with Excel 2003 to Vista based PC with Excel 2007, the old macros do not work. Please help me to activate the macros. Thanks Sdharmarajan


View more questions Search