+ Reply to Thread
Results 1 to 15 of 15

Search Image from a Folder

  1. #1
    Registered User
    Join Date
    08-02-2009
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2003
    Posts
    18

    Search Image from a Folder

    Hi to everybody, im a total novice in Excel programming.

    I really need a macro that from a targeted folder, if i write an image filename in a cell box, that image is showed in a Image control box.
    (Images are all in .jpg)

    Somebody can help me please?


    Thank you in advance for your help.

  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: Search Image from a Folder

    Hello AiKuchi,

    This macro will take the file name from cell "A1" on "Sheet1" and display in it in a Control Toolbox Image control on "Sheet1". The Image control will size itself to match the picture. If you need to change the worksheet name, cell, or name of the control, they are marked in red.
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    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
    08-02-2009
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Search Image from a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello AiKuchi,

    This macro will take the file name from cell "A1" on "Sheet1" and display in it in a Control Toolbox Image control on "Sheet1". The Image control will size itself to match the picture. If you need to change the worksheet name, cell, or name of the control, they are marked in red.
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Thank you so much for your help Leith.

    I placed a Image control box on the sheet1 and then I followed your precise instructions and when i try to run the macro, i have this debug problem in the line:


    Please Login or Register  to view this content.

    Runtime error: 76:

    Path not found



    Thank you 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: Search Image from a Folder

    Hello AiKuchi,

    The error is because Excel can't find the file. Check the spelling of your file path (folder) and the file name.

  5. #5
    Registered User
    Join Date
    08-02-2009
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Search Image from a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello AiKuchi,

    The error is because Excel can't find the file. Check the spelling of your file path (folder) and the file name.

    Hello Leith,

    I checked the path (C:\images\) but it's right.

    The error is: File not found.

    in the same line
    Please Login or Register  to view this content.
    But inside the folder there are many image files (.jpg)
    For example 01.jpg

    Thank you.
    Last edited by Aikuchi; 08-02-2009 at 08:06 AM.

  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: Search Image from a Folder

    Hello AiKuchi,

    The file name must be typed in cell "A1" before you run the macro. You said...
    [quote]
    I really need a macro that from a targeted folder, if i write an image filename in a cell box, that image is showed in a Image control box.
    [/code]
    I understood "cell box" to be a cell, like "A1", on the on the worksheet.

    Chigai de gozaimasu ka?

  7. #7
    Registered User
    Join Date
    08-02-2009
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Search Image from a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello AiKuchi,

    The file name must be typed in cell "A1" before you run the macro. You said...

    I really need a macro that from a targeted folder, if i write an image filename in a cell box, that image is showed in a Image control box.

    I understood "cell box" to be a cell, like "A1", on the on the worksheet.

    Chigai de gozaimasu ka?
    Iie so desu. Cell Box desu

    Yes it's right, the filename must be in a cel box, like "a1".

    But i don't understood when i try to run the macro, there is always this error. But it's all right

    Arigatou Gozaimasu.

  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: Search Image from a Folder

    Hello AiKuchi,

    Daijobu ku nai.

    I am attaching a workbook with the macro. Type the file path into "A2" and the file name into cell "B2" and click the button. The image button will display the file. If an error occurs then a dialog window will display the error number, description, the file path, and file name.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-02-2009
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Search Image from a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello AiKuchi,

    Daijobu ku nai.

    I am attaching a workbook with the macro. Type the file path into "A2" and the file name into cell "B2" and click the button. The image button will display the file. If an error occurs then a dialog window will display the error number, description, the file path, and file name.
    Please Login or Register  to view this content.
    Hountouni arigatou gozaimasu Leith San!

    The macro works perfectely!

    Just a one thing if possible.
    There is a way for write just the filename without to write everytime the file extension?

  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: Search Image from a Folder

    Hello AiKuchi,

    Dou itashimashita. Hai, so deshou.

    I changed the code to automatically add ".jpg" to the file name. The change is in blue text.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-02-2009
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Search Image from a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello AiKuchi,

    Dou itashimashita. Hai, so deshou.

    I changed the code to automatically add ".jpg" to the file name. The change is in blue text.
    Please Login or Register  to view this content.


    Yokatta ne!

    Domo, hontouni arigatou gozaimasu Leith San!

    Mata ne

  12. #12
    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: Search Image from a Folder

    Hello AiKuchi,

    Dozo yoroshiku, AiKuchi san. Ima code wa, warkarimashita ka?

  13. #13
    Registered User
    Join Date
    08-02-2009
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Search Image from a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello AiKuchi,

    Dozo yoroshiku, AiKuchi san. Ima code wa, warkarimashita ka?
    Hai wakarimashita

    Yokatta.

    Mai domo Leith San. Anata no nihongo hontouni sugoi des ne!

  14. #14
    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: Search Image from a Folder

    Hello AiKuchi,

    Yes, my Japanese is rusty. I lived in Japan for four years from 1980 - 1984. I lived in Kanagawa-Ken, Zushi Kaigan, near the emperor's summer palace. Loved it there.

  15. #15
    Registered User
    Join Date
    04-21-2015
    Location
    Köln,Germany
    MS-Off Ver
    2010
    Posts
    40

    Re: Search Image from a Folder

    Hello,

    I have a userform with a textbox field, a search command button, and an image. I am trying to find code to so that I can search for a file name (the picture name should be written in textbox) from a file on the computer of an image that will then cause that image to come up in the image once the command button is clicked. I am a novice at VBA/Macro. The images are all located on the C drive. Any help would be greatly appreciated.

    Thanks,

+ 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