+ Reply to Thread
Results 1 to 15 of 15

Inserting images based on an Excel list of items

  1. #1
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Inserting images based on an Excel list of items

    I want to create an Excel workbook that will read lists of items from another workbook and create new worksheets in our new workbook populated with images and their titles based on the contents of the other workbook.

    To explain this further:

    I have a workbook with several worksheets. We'll call the workbook BookA and it's sheets SheetAA, SheetAB and SheetAC for reference.

    Each of these worksheets has a list of items in column A, starting at cell A15.

    Each item in this list may have up to three images associated with it (though there may also be none).

    All images for all sheets are stored in the same folder for a given version of BookA, and all images are of the same dimensions.

    Image names are based on the item name with one of three postfixes, for example:
    'item_name_001' may have images named 'item_name_001_P.jpg', 'item_name_001_C.jpg' or 'item_name_001_S.jpg'. The postfixes are always an underscore followed by 'P', 'C' or 'S' and the .jpg file extension.

    For each of the desired sheets in BookA, I want to run down the item list in order and identify if each of these associated images exist in the folder. If it does, I want to import it to the new workbook in a correspondingly named new sheet.

    For these new sheets, the image layout is important. The images must span 3 columns. The first image should be placed in cell A1, the second in B1 and the third in C1. Where more than one image exists for an item, they should be ordered 'P', 'C', then 'S' (from the image name postfix). If there are only one or two images for a given item, then the next item's images should immediately follow it in the row until we reach our maximum of column 3, then wrap down to the second row below.

    Each image also requires the image name to be placed in the cell immediately below it.

    Thus we have 2 rows of 3 columns for each row of items - a row of 3 images with a row of 3 image names underneath. That is:

    Cells A1-C1 contain 3 images.
    Cells A2-C2 contain 3 image titles.
    Cells A3-C3 contain 3 images.
    Cells A4-C4 contain 3 image titles.
    ... and so on until the end of a sheet's list of items.

    The image dimensions are constant, but do need scaling from the original size. The ideal is for them to remain 8.5cm height while maintaining their aspect ratio (the current manually created version I'm looking at has an image size of 8.49cm x 11.32cm, though no doubt there's some rounding to that).

    Currently on my manually created sheets, a row height of 240 for the images and 15 for the titles looks about right for Arial 8 point text for the titles.

    I'd like to be able to select BookA's title and location, and also the source directory for the images to be used. Having done so, our new workbook should generate corresponding SheetAA, SheetBB, SheetCC populated with our images in the format above. No other information is needed on these sheets.

    The explanation sounds more complex than it really is when you break it down but I wanted to be as clear and specific as possible. Sadly my VBA skills aren't quite up to this as I've not used it in years.

    Note the reason for my wanting a new workbook to generate these populated sheets is to avoid putting any code into the original source document, that needs to remain 'clean'.

    Thanks in advance for any assistance with this, it will be a huge timesaver for me.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Inserting images based on an Excel list of items

    attach please a sample file
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    See attached for a sample.

    This contains three sheets with list data similar to my needs, and one of the image sheets has images that correspond in an appropriate layout to what I want to achieve.

    Note that the worksheet names are always consistent, so its safe to assume that SheetAA will always be called SheetAA etc.

    Sorry, didn't realise I could upload a file to the board which obviously makes this easier to understand.
    Attached Files Attached Files
    Last edited by Antiriad2097; 08-15-2013 at 03:57 PM.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Inserting images based on an Excel list of items

    Your goal is not clear for me, what is desired result ?

  5. #5
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    To read the list of items from cell A15 downwards in SheetAA (and the other similar sheets).

    Each item may have one or more corresponding images in a folder.

    Search this folder to find a matching image (if one exists) and insert it in the image sheet in the format shown in the sample file. There may be up to 3 images for each item in the list and all of these must be inserted if they exist. Each image will have the same name as the item in the list, with one of 3 extensions added to the string: _P.jpg, _C.jpg or _S.jpg.

    In pseudocode:

    Start at list in cell A15.

    Read first item in list.

    Search folder for image ItemName_P.jpg

    Insert image in image sheet if it exists and add image name in the cell below. If image doesn't exist, search for next image.

    Search folder for image ItemName_C.jpg

    Insert image in image sheet if it exists and add image name in the cell below. If image doesn't exist, search for next image.

    Search folder for image ItemName_S.jpg

    Insert image in image sheet if it exists and add image name in the cell below.

    Move to next item in list and repeat until end of list.

    Move to next sheet with a list and repeat the above for a new sheet of images.

    Every row of images should contain 3 images, even if this is two for one item and a third for a different item for example (ie it loops round filling the images from A1 to C1 regardless of what they are). Images will be placed in cells A1, B1, C1, A3, B3, C3, A5, B5, C5 and so on, with image filename in A2, B2, C2, A4, B4, C4 and so on.

    Do this for all sheets containing lists. Sheet names are constant, so can be hard coded.
    Last edited by Antiriad2097; 08-16-2013 at 10:29 AM.

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Inserting images based on an Excel list of items

    Start at list in cell A15. - OK
    Read first item in list. - OK
    Search folder for image ItemName_P.jpg - folder ? where ?

  7. #7
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    I'd like to be able to select the source workbook for the list data, and also the source folder for the images, then run the script to generate the sheets full of images.

    Doesn't matter too much to me how this is done, whether its via the Windows file dialogues or simply copy/pasting the paths into a cell (much easier to do that than mess around with dozens of images repeatedly on a daily basis). A file selection dialogue would be nice but far from essential.

    As per my first post, ideally I want to run this code in a standalone workbook so it doesn't impact on my workbook with the list data in any way other than reading from it.

  8. #8
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    Ok, lets simplify this.

    How can I search an Excel list, then search for a corresponding image in a predefined folder?

    Assume images are in C:\Images\

    Item list starts in Cell A15.

    We'll assume item names are the same as the image names, minus the .jpg file extension.

    My main issue is to check for the existence of an image and return a true/false response to act on that further. I don't know how to parse the list to add the .jpg extension then test for the existence of the image file in a folder.

  9. #9
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Inserting images based on an Excel list of items

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    That's great, thank you, a big help.

    Next step: How do I then load that image and place it on a page in Excel, with a height of 8.5cm and maintaining the aspect ratio?

    With these two things it should be relatively simple to put the rest together.

  11. #11
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Inserting images based on an Excel list of items

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    Well, thanks to your pointers and a little Googling, I have a working solution now.

    It needs a final tidy up to set the column and row sizes that the images are placed in, but otherwise its working as intended during my brief tests.

    Here's the final code I came up with:

    Please Login or Register  to view this content.
    I can now expand on this to search other data sheets and compile multiple image sheets. This has been a nice little learning exercise.

    The code isn't too pretty or advanced, but it does what's needed of it. Any pointers to tidy things up or make it more compatible with other versions of Excel would be nice but not necessary, so don't feel obliged.

  13. #13
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    I've discoverd my code above has version issues.

    It works fine on my own PC using Excel 2003, but a colleague using a later version finds it will somteimes insert a linked image instead of embedding it. That's fine while we're working on the network, but as soon as we take the files offline our images only show the link - see the attached jpeg for an example (I've blurred most of the file path for anonimity).

    Can anyone suggest a fix to my pasting code that will force the image to be embedded instead of linked?
    Attached Images Attached Images

  14. #14
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Inserting images based on an Excel list of items

    I'm using excel 2010, your final code works well on my test sheet on local drive.
    need a sample file for testing

  15. #15
    Registered User
    Join Date
    08-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Inserting images based on an Excel list of items

    It does appear to work as long as the images in the folder are available and the workbook can access those. Move the images (or rename the folder) and you'll find that the images in the workbook will randomly appear as links instead of being embedded. There doesn't appear to be any consistency to when this will happen.

    Its possible to spot the affected images - if you double click them once inserted in the spreadsheet to bring up their properties, the path will appear in the 'web' tab if it's been linked instead of embedded.

    I've resolved it by changing the section of code that pastes the image to:

    Please Login or Register  to view this content.
    This seems to work on both the old and new versions of Excel and is much neater, though it doesn't fit the image to a cell but to a specific location on the page instead. I'm seeing a slight misalignment vertically once I get down to row 10 but its rare I need that many.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Drop Menu/List of Icons/images that look and work like any Excel Meun Items.
    By dallen2408 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-19-2013, 09:34 PM
  2. [SOLVED] Inserting Images into Excel
    By JungleJme in forum Excel General
    Replies: 1
    Last Post: 06-08-2012, 10:21 AM
  3. Inserting images into a cell based on another cells value.
    By ccScotty in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-04-2012, 12:08 PM
  4. inserting images in excel automatically
    By leonachs49 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2009, 08:51 PM
  5. [SOLVED] Inserting images into excel conditionally
    By Pav in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-16-2005, 06:00 AM

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