+ Reply to Thread
Results 1 to 15 of 15

How to import picture file from folder using cell value?

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    How to import picture file from folder using cell value?

    Hello,

    I am trying to create new excel file where I need to import picture file based on cell vale.

    for example: at cell A1 I will input item number (i.e. 12345, 23456, 34567 etc.) and at cell B1 or anywhere in that spreadsheet I need associated picture.

    I will have all associated pictures in one folder with picture name same (i.e. 12345, 23456, 34567 etc.): C:\Documents and Settings\User\Desktop\Pictures

    How to go from here?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to import picture file from folder using cell value?

    Hello kaypat,

    This macro should get you started. This will import the file using the name in the active cell. If the file is found in the specified folder, it will be inserted with the upper left corner of the picture in the cell to right of the active cell. The macro does not size the picture. It is inserted at full size. Als, the macro expects the picture to have a jpg extension. If your pictures have a different extension, it will need to be changed in the macro code.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-02-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to import picture file from folder using cell value?

    Thanks Leith. I will try this.

    Question: In macro instead of ActiveCell, should I put cell location (i.e. A1 or B1)?

    If not then, what formula should I put where I want picture?

    Thanks again.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to import picture file from folder using cell value?

    Hello kaypat,

    I used ActiveCell only as example. If you have a specific cell in mind, say "A1" with the file path and name, then the code would be as below. This will place the upper left corner of the picture in cell "B1".
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-02-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to import picture file from folder using cell value?

    Leith,

    When I rum macro using this code I get Run-time error '1004': (I have attached Picture 1)1.JPG

    And when I do Debug, it highlight following line in code: (I have attached picture 2) 2.JPG

    Set Pic = ActiveSheet.Pictures.Insert(Filepath & ActiveCell)

    Thank you for your help!

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to import picture file from folder using cell value?

    Hello kaypat,

    It appears that the Picture class has been dropped from Excel starting with Excel 2007. Here is another way that should work.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-02-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to import picture file from folder using cell value?

    Great. This works!
    Thank you again!!

    I have couple of questions if that's not too much to ask

    Can macro re-size picture automatically to fit within certain rows & column or in text-box?
    Can this macro run automatic (i.e. as soon as I enter value in cell A1 it imports picture)?
    Also, when I ran macro using one cell value (A1) it imported associated pic and when I changed cell value it imported new cell value picture but over old pic (i.e. it did not over-write on old pic or it did not delete old pic before importing new pic)? Is it possible to delete old cell value pic while importing new cell value pic?

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to import picture file from folder using cell value?

    Hello kaypat,

    Yes, yes, and yes. Would you like me change the macro to do this? My guess is yes.

  9. #9
    Registered User
    Join Date
    02-02-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to import picture file from folder using cell value?

    I would be really grateful if you would do that for me?

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to import picture file from folder using cell value?

    Hello kaypat,

    Here is the revised macro to copy the image from a file into a range of cells. The previous picture will be deleted before the new picture is added.

    The attached workbook will import the picture using the contents of cell "A1" on "Sheet1" as the file name. The macro assumes all files are a jpg type so do not add ".jpg" to the file name. The picture range is cells C2 to E14. The picture will be sized automatically to fit the cells in the range.

    There are now two macros. One is the Worksheet_Change event for "Sheet1" which checks that you entered a value into cell and calls the import picture macro. The import picture macro then adds the picture from the file to the worksheet and resizes it to fit the range.

    Worksheet_Change Event Macro Code
    Please Login or Register  to view this content.
    Import Picture To Range Macro Code
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    02-02-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to import picture file from folder using cell value?

    Hey Leith,

    Your attached file doesn't work for me?

    All I did was changed file path to where I have pics located but it does not do anything! What am I doing wrong?

  12. #12
    Registered User
    Join Date
    02-02-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to import picture file from folder using cell value?

    Hello Leith,

    I was finally able to figure it out.

    As when you type cell value at A1 and enter.....macro would run automatically to import picture per your code however when ImportPicture macro runs active cell now is A2 (since I hit enter after typing value)......it did not import picture!

    What I did is defined cell value A2 equals A1 and highlighted in white you so don't see it..........with this trick macro does it trick per your code!!

    Thank you for your help with this code!

  13. #13
    Registered User
    Join Date
    01-24-2013
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How to import picture file from folder using cell value?

    Hey all,

    I'm trying to use this as well - this isn't set up to work for an entire column, is it? Just the first cell?

    How would I go about changing it so that all values in A:A pull up an image directly to the right of them?

    Thanks for any help you can offer,
    -Dan

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to import picture file from folder using cell value?

    dlac,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  15. #15
    Registered User
    Join Date
    01-24-2013
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How to import picture file from folder using cell value?


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1