Question:

Insert a picture with macro in Excel?

by  |  earlier

0 LIKES UnLike

Hello

I would like to design or create a macro that will import a picture (jpeg) in my Excel page, When using the macro registration tool, the import function is not taken in account. When registering the macro, the imported picture is showed on the page, but when i recall the macro, the import section is not present, only the movement of the mouse.

Hope my English translate well my problem.

M.Theriault

 Tags:

   Report

1 ANSWERS


  1. When I recorded an Excel 2003 macro importing a jpeg image this is the code that was generated

    ActiveSheet.Pictures.Insert ("C:\Pictures\house_logo.jpeg").Select

    That code (all on one line with no spaces) imports the picture and places it at the location of the currently selected cell.  

    When I dragged the picture to a different location the following code was generated:

    Selection.ShapeRange.IncrementLeft 146.25

    Selection.ShapeRange.IncrementTop 56.25

    And if you watch the worksheet while you step through a macro with all of the above code, you can see it happening.

    __________________________________

    Excel 2007 does not record the insertion of a picture into a worksheet but code that will work is

    Sheets("Sheet1").Shapes.AddPicture "file path &name", False, True, 10, 10, 400, 400

    The parameters are all required

    Filename, LinkToFile(T/F), SaveWithDocument(T/F), Left, Top, Width, Height

    Search for Shapes.AddPicture Method in Help for more discussion.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.