+ Reply to Thread
Results 1 to 37 of 37

Lookup Images with VBA

  1. #1
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Lookup Images with VBA

    I have a cabinet quotation spreadsheet that offers 22 door styles. We never need to quote more than 6 or so. showing all 22 doors is impractical now. What I want to do is make 6 selections from 6 pull down menus (menues showing all 22 door styles). Upon making a selection for door 1, I want it's image to appear. Same for door selections 2 through 6.

    I did find some code from McGimpsey & Assoctiates (http://www.mcgimpsey.com/excel/lookuppics.html), that works, however, it is only good for 1 image per tab. My application needs mulitiple selections as described above.

    My question \ request, is how do I modify the McGimpsey code to allow for multiple images to be controlled by a pull down menu?
    Last edited by Michael Marshall; 08-28-2009 at 12:01 PM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Lookup Images with VBA

    This approach is a bit different from McGimpsey, but it works. See attached workbook - which only contains six images, which themselves were all sized to exactly the same dimensions to aid consistency in display.

    Each of the shaded cells used a Data Validation list to present a numeric selection range.

    You will need to copy and paste all images into the worksheet. I've used the Excel default name of Picture X (where X = a number).

    The code joins this fixed string "Picture " to the number selected in the cell to determine which picture to display next to the selection.

    Please Login or Register  to view this content.
    HTH,

    Palmetto
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Palmetto, thanks for the quick help. I suspect that for me to change the entries in my validation list to user friendly names like "Fallbrook", I need to name the picture "Picture Fallbrook"...?

  4. #4
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Lookup Images with VBA

    I suspect that for me to change the entries in my validation list to user friendly names like "Fallbrook", I need to name the picture "Picture Fallbrook"...?
    Well, to make it work with the code as given, you could just create a look up table.

    Column-1 of the table = "Friendly Name" and is the list of items in the drop down.
    Column-2 of the table = sequential numbers
    Column-3 (optional) - could be a cross-reference between the "friendly name" and the default Excel name of Picture X.

    This approach requires that you use a look up formula to match the friendly name to its associated number.

    The code would have to be adjusted to reference the results of the look up cell.

    When you add the pictures to the worksheet, Excel uses a default name of Picture X ( as I pointed out earlier). I would opt to minimize the work and simply use the default name because it will work with code as given.

    You can rename a picture by selecting it and typing a new name for in in the name box but this will mean major revision to the code.

    See attached - revised per above approach.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Ok, so I have all of the pictures tied to the code and my validation list. I ran into a couple issues though. When I would select a new door, if there was an existing door...the existing door may have an "Order" that places it on top, leaving my newly selected door behind... So I added a like of code to place the newly selected door "On Top".

    While this helps...I still have an issue. Since there are always doors showing, If I select a door as an alternate that is already used in a different alternate...It'll move the image, but the previous alternate will still show the name of the door, but show the door that was below. I attached the spreadsheet so you can see what I mean.

    The doors almost need to be invisible unless they are explicitly selected, and get positioned where they are selected.... Not sure how to do that. Hope you have a thought on this.

    Oh, I also changed the positoning coordinates for Left & Top to serve my layout.
    Attached Files Attached Files

  6. #6
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Lookup Images with VBA

    Try this amended code: Once a selection is made, it will check to see if there are any cells that already have that selection and, if so, set them to "No Selection", which removes the duplicate text and makes the default picture appear.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    First...thank you for being so patient. I dropped the code in and tried to pick the same door for two selections to test the new changes. There appears to be some sort of circular reference...the image literally moves back and forth between the two selections until I hit escape to bring up the debugger.

  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,259

    Re: Lookup Images with VBA

    Hello Michael Marshall,

    Here is a more direct approach using a Control Toolbox Image Control object. The Image Control makes it simple since the pictures can be loaded into it directly from a file. It also takes care of the sizing automatically.

    I created a folder with your door panels saved in jpg format. The file names are the same as the names in validation lists. This folder should be located in the same folder as the workbook. Here is the worksheet macro code. This has already been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    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!)

  9. #9
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Lookup Images with VBA

    OK. This is tested and works as needed. Give a try.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    What is the relationship with "Image#.Picture" and the image. I'm asking because I would need to make about 6 descrete selections...

  11. #11
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Nevermind...I got it. It's working correctly with the additional image control added. Is there any way to have this work and have the images contained IN the actual spreadsheet as apposed to in the same folder that the spreadsheet resides in?

  12. #12
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Lookup Images with VBA

    Is there any way to have this work and have the images contained IN the actual spreadsheet as apposed to in the same folder that the spreadsheet resides in?
    Seems you haven't tried my amended code/workbook, which works with the images in the sheet and now resets the image to "No Selection" when a duplicate selection is made in another drop down.

  13. #13
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    If the images need to reside outside the spreadsheet, is possible to have it point to a shared directory or does it have to be in the same folder as the spreadsheet. I'm asking, because there are several people who use this quotation sheet.

  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,259

    Re: Lookup Images with VBA

    Hello Michael Marshall,

    The images can reside in another folder. When zipping files it is easier to code this way. Once the files are unzipped, they are all in the same folder. Let me know how you want it setup and I'll modify the code accordingly.

  15. #15
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    So they can exist in another folder, but not in the actual spreadsheet....right? So if I wanted to email it to someone...I'd have to send the folder (like you did for me)..? If so, I think I can live with that...actually gives a little control over the spreadsheet once it leaves the facility.

    So yes, the new directory would be on our server...I just dont know how to map that in the code. \\ServerName\folder.....???

  16. #16
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    The path for where I'd like it to be is:

    \\Pcsfile01\Design\DESIGN & ENGINEERING\Order & Bid Masters\Door Panel Pictures\

    OR

    L:\DESIGN & ENGINEERING\Order & Bid Masters\Door Panel Pictures

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

    Re: Lookup Images with VBA

    Hello Michael Marshall,

    You just need to change the path(DoorPath) like this...
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Ok...it worked. Thanks a ton. And just so I understand...this approach cannot be executed by refering to them within the spreadsheet. Said another way...is there a way to have the images saved in the spreadsheet (self contained..portable and ready to go), or does it have to refer to an outside directory?

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

    Re: Lookup Images with VBA

    Hello Michael,

    The Image control has a native method to load the picture but is restricted to using an external file. I do have code that can copy and paste a picture to any object that supports pictures. I would need to add this to the current project, if you want the pictures in the workbook.

  20. #20
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    If you think it's worthwhile...trust me, I'm super gratefull for having got to this point. The behavior of the spreadsheet is working flawlessly...just how I wanted. Having the images outside the spreadsheet just makes me suspect that I may be getting phone calls later from people outside our network.

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

    Re: Lookup Images with VBA

    Hello Marshall,

    It isn't a problem. I have just transferred all the pictures from the folder back into the workbook. Once I get the code updaed, I'll post the code and the revised workbook.

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

    Re: Lookup Images with VBA

    Hello Michael,

    The macro now copies the pictures from "Sheet2" and pastes the picture into the appropriate Image control for the Validation drop down. I have added a button which renames the pictures using the door names. The original picture name is in column "A" and the new door name is in column "B". All the named ranges are on "Sheet2" also. This is what the new macro for "Sheet1" looks like. The attached workbook has all the new updates.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Absolutely perfect!!! The boss is VERY happy... To both Leith Ross and Palmetto, thank you for taking the time work this out with me. My turn to help someone out with some non-vba stuff. Thanks again gentlemen.

  24. #24
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Lookup Images with VBA

    Glad you got the solution you needed.

    Please be sure to mark your thread as solved and don't forget to click on the "scales" icon to add to the reputation of those who helped.

  25. #25
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Certainly!!!! How do I flag it as solved though?

  26. #26
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Lookup Images with VBA

    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

    To add to the reputation:

    On a post to which someone has responded, click the "scale" icon. It is self-explanatory from there.

  27. #27
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Leith,

    I copied the sheet and all of the images into the actual functioning quotation sheet and it doesnt work now. The validation list is good..., just no image change after I make the selection.

    I suspect that there was some spreadsheet \ worksheet specific variables in the code that need to be redefined to adapt to the new placement.... Can you tell me what they are? The code that you gave me that was working perfectly (that is still in the new spreadsheet) is:
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 08-31-2009 at 12:13 PM. Reason: Added Code Tags

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

    Re: Lookup Images with VBA

    Hello Michael,

    If you aren't getting any error messages then the problem is with your named ranges. Check the named range in each validation list. Be sure they match the addresses you have on Sheet2. If you still have problems, I will need to see the workbook.

  29. #29
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Validation lists are clean. When I debug, it's on the below line:

    Case "$C$6"
    Image1.Picture = PastePicture

    Of course C6 is where I was making my selection just before the error came up. Also noteworthy... when I put my cursoor over "PastePicture" in the code...I get a tool tip message saying "PastePicture = Empty"

  30. #30
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Ok Leith, I took the functioning spreadsheet you gave me and simply copied the information to another spreadsheet. I did this so you can see how it no longer works... If you can figure out how to fix this attachment...I suspect you can tell me how to fix the my quotation sheet.

    Michael
    Attached Files Attached Files

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

    Re: Lookup Images with VBA

    Hello Michael,

    You forgot to include the module that has the PastePicture macro. The attached workbook has been corrected.
    Attached Files Attached Files

  32. #32
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Ok, so I managed to get hung up again. This attachment has the code, and has the module like you said, yet still has an error... I'm sorry for being such a pain...
    Attached Files Attached Files

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

    Re: Lookup Images with VBA

    Hello Michael,

    I downloaded the file and it runs with no problem. What is the problem you're experiencing?

  34. #34
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Run-time error '424'

    Object required.

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

    Re: Lookup Images with VBA

    Hello Michael,

    I think I found the problem. There are 2 selection which don't have pictures: Shaker Maple and No Selection. I have attached a file that traps the error if a picture is missing. Here is the updated code.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  36. #36
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Leith Ross...you're the man.... It's working now. I was getting a compiler error: Ambiguous Name.... So I checked my modules, I copied the PastePicture macro over more than once.. Thank you sooooo much for not throwing in the towel!!

  37. #37
    Registered User
    Join Date
    08-25-2009
    Location
    Ontario, CA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Lookup Images with VBA

    Leith,

    You helped me with a spreadsheet a while back and since then, haven't needed to use it much. It has come back to me and I am using Excel 2007 now...not sure if this is why the image control you helped me with doesnt work now.

    I attached a simple example of what we last worked on. For some reason, the names of the images are not being matched or something. If you could help me out with this, I'd appreciate it!
    Attached Files Attached Files

+ 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