Excel Macro help with inserting a picture into a rectangle?

Greetings. I am currently struggling to get an Excel Macro to work. What it must do is the moment you select the rectangle it display the "File insert diagram" and then after you selected the image it must insert the image into the selected shape. Here is an example of the code i was trying to combine but i keep on getting debug errors

##Code 1:

Sub AddPic()

Selection.ShapeRange.Fill.UserPicture _

"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg"

End Sub

In the above code, i need a string instead of a default picture to be inserted, the file insert must pop up where you usually browse for a picture and then insert it into the selected range

##Code 2

Picture = Application.GetOpenFilename(ImgFileFormat)

I have searched and attempted many pages but i could not find a solution to this problem and if anyone can help me in this code it would be much appreciated.

In short here is a summary of what it must do

1. You select the rectangle shape

2. You click the button with the macro assigned to it

3. The fileopen dialogue appears and you browse for the picture

4. It gets inserted into the shape



2 Answers

  • 8 years ago
    Favorite Answer


    This works for me:

    Sub AddPic()

    On Error GoTo cancel:

    'Only leave Application.GetOpenFilename if you don't want the default search restricted to JPG files

    Picture = Application.GetOpenFilename(".jpg Files (*.jpg), *.jpg")

    Selection.ShapeRange.Fill.UserPicture Picture


    End Sub


  • 4 years ago

    oh dont think of u can with that cellular,srry yet u can if u deploy the excell 2007 u can pass to the cellular place and deploy it there the place ever u offered the cellular.. wish this facilitates chum!

Still have questions? Get your answers by asking now.