+ Reply to Thread
Results 1 to 26 of 26

Finding specific picture in a specific folder and insert it somewhere specific

  1. #1
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Finding specific picture in a specific folder and insert it somewhere specific

    I want to create a macro that look a specific cell and find the picture with the same name in one particular folder and insert it into a specific shape.

    1637802847699.png

    For exemple, I want the macro to insert the picture that is called PIC1 from the dedicated folder in the first square, the picture that is called PIC2 from the same dedicated folder in the second square and so on for as many picture as needed.

    Also, I would like the macro to find them and insert them all in only one click.

    Can someone help me ?

    Thanks !

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Please Login or Register  to view this content.
    It can also be done with just the info you supplied in your Post but then we need to know the correlation between picture names and shape names.
    If the picture name would be in Cell B2 and the left top cell of shape where that picture needs to go into would be one cell below that.
    Or the shape name would be in the cell below (or beside it or whatever) it

  3. #3
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Thank you it worked ! But its still to time consuming if I have like 60+ photos to enter ! My next question is below ↓

    Please Login or Register  to view this content.
    ***Another question, if we select all the shapes in a worksheet, will they have an order ? Because if yes, we could replace shpArr with a selectAll function so we don't have to write their name one by one also.
    Last edited by davesexcel; 01-29-2022 at 09:55 AM.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Your question was:
    "I want to create a macro that look a specific cell and find the picture with the same name in one particular folder and insert it into a specific shape."

    What you say now is a different story.

    Explain in a consise manner what you want to achieve.

    For instance:
    I want all the pictures in a folder to be imported into a sheet and put under each other with the top left cell of the picture in Column B.
    The pictures need to be sized to be 6 rows in height and 8 columns in width
    There need to be one empty row between pictures.
    If you want to stick with rectangles, we need to know which picture goes into which rectangle (obviously I would say).
    It is slow is because of the lack of information or the setup.

    Maybe the attached, that I had hanging around, will give you an idea.
    Select a couple hundred pictures and see how slow/fast it is
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Sorry for not being clear enough !

    Capture2.PNG

    The ideal scenario would be that the macro would look in the Range("A") and keep in memory every data that is in the column in order. As in the picture, it would be ("PIC001", "PIC056", "PIC099" etc.) Then, I want the macro to look in a specific folder to find the pictures with the same name as in the column A and insert it in order in the shapes on the other page. So PIC001 with the first rectangle, PIC056 with the rectangle under etc.

    I want the selection of the pictures and the rectangles selection to be fully automated. Same for the picture inserting. I dont' want to have to enter anything by hand except the value in the column A.

    I hope I am clearer !
    Last edited by Programmer24; 11-26-2021 at 11:11 PM.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Are the rectangles named, from top to bottom like "Rectangle 1", "Rectangle 2". "Rectangle 3" etc or just any name?
    It looks like the Rectangles are pretty well under one another but are all the top left cells of each rectangle in the same column?
    It looks like they are not right in the corner of the cell.

    Code assumes that the rectangles are named "Rectangle 1", "Rectangle 2", "Rectangle 3" and so on.
    Change references (Sheet names, cell addresses, path, picture extension) as required.
    Please Login or Register  to view this content.
    Last edited by jolivanes; 11-27-2021 at 02:12 AM. Reason: Add code

  7. #7
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    It works perfectly fiine ! And its ok to say that the rectangles are named in order like 1, 2, 3, 4, 5 etc because that I will set 1 time and the workbook will be a template, so you set it only one time and its done for further use.

    Now, is it possible to say that if the macro does not find a picture for the FUN488 for example, that it skips to the rectangle below and search for its next associated picture.

    Capture.PNG

    If I don't have a picture to put in rectangle 2 that is called FUN488 (sometimes I don't have any pictures at all) I want the macro to skip it and go see if the rectangle 3 have a picture that is called FUN002 in the folder. Now if it doesn't find a picture for rectangle 2 I get an error and it will stop there and won't give me a picture for the next rectangle.

    Note that the code above works fine except if I don't have a picture for all the FUN numbers that I have. If I have less pictures (2 in this example) than the exact number in the A column (less than 3), I get an error when it does not find anything.

    Thanks for ur time we are close to the goal
    Last edited by Programmer24; 11-27-2021 at 02:23 PM.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Change the macro to
    Please Login or Register  to view this content.
    You can spot as many rectangles as you want like this
    Please Login or Register  to view this content.
    If you want to delete them, use this
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Everything is perfect ! But I would need to know how to modify the code so it accepts .jpg and .PNG ?

    Plus, I would need to know how to space out the rectangle as I want Ex. I want the first one to be on B41 and the others need to be spaced out of 28 cells. So B41, B69 and so on.

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Try this for pictures with different extensions and possible pictures missing.
    Remember to change references like Sheet names etc where needed.
    Please Login or Register  to view this content.

    To start at Row 41 (B41), change this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    and to have a space of 28 cells, change this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    and this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    so you will end up with this

    Please Login or Register  to view this content.
    You must have noticed that the rectangles are named starting at 1 for the first rectangle and increase by 1 for each subsequent rectangle.
    Last edited by jolivanes; 11-27-2021 at 06:35 PM.

  11. #11
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Everything is perfect ! Thank you a lot for your help I don't have any more questions for now :P

    Have a nice evening (from Canada)

  12. #12
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Thanks for letting us know that it all worked out and glad you've got it all sorted.
    Enjoy your weekend (from Edmonton) and stay safe.
    Good luck

  13. #13
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Hello jolivanes !

    I was wondering if we could add a little tweak to the code sequence :

    Step #1 would be this (inserting rectangle):

    Please Login or Register  to view this content.

    Then we would use this to insert pictures :


    Please Login or Register  to view this content.
    That were the codes you created for me ! I have been using them almost every week since the last time we chatted, but I would like it more compact !

    I would like to combine both code so that it can follow these next steps :

    1. Check if the string in the cell is matching the picture name in the folder. If it can't find a match then do nothing

    2. If it finds a match, create the rectangle and insert the picture in it.

    3. Repeat the first steps like the actual code until it imported all the pictures .


    In step 1, If am only actualising the picture I would like that :

    If there was a picture that I don't use anymore, I want the code to delete the rectangle and the picture.

    So it would be like :

    Check if there is a rectangle, if yes, check if you have a match, if no match then delete rectangle and go to the next one.

    If rectangle is yes with a match, insert the picture in the rectangle and if there is no rectangle with a match, create one and insert the picture in it.

    The rectangle's name shall stay Rectangle 1, Rectangle 2 and so on like it is already.

    Hope you can understand what I mean and help!

    Thanks in advance
    Last edited by Programmer24; 01-28-2022 at 01:07 PM.

  14. #14
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Re: "If it finds a match, create the rectangle and insert the picture in it."
    This means that there was no rectangle.

    Re: "Check if there is a rectangle, if yes, check if you have a match, if no match then delete rectangle and go to the next one. If rectangle is yes with a match, insert the picture in the rectangle and if there is no rectangle with a match, create one and insert the picture in it.
    This means there are rectangles.

    Would it not be better to check if the picture exist in the folder, if it does not, go to the next cell with picture name.
    If it does exist, make a rectangle and insert the picture into it.
    That way you don't have to add and/or delete rectangles. This would probably also result in having possibly large empty spaces between pictures.

    Or am I misunderstanding your new request?


    Forgot to ask if the rectangles are there to size the pictures? You can insert pictures to be the same size as the rectangles in the same range where the rectangles are.
    Last edited by jolivanes; 01-28-2022 at 05:42 PM.

  15. #15
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Ok so, normally, I would insert my rectangles first with the macro that does it. Then, run the code that check a match with the cell and the picture name in the folder.

    Now I would want something like this :

    Check If in the Sheets("Sheet1"), the Range("D1") have a match with a picture that goes by the same name in a (specific foler) Then (if true)

    Insert the picture cropped to 100 x 100 in the cell B41 of Sheet2 '----- Start at 41 and add 28 each time after (same as previous code)

    Else

    Do nothing and skip to the next

    Loop that for Range("D1:D100") in Sheet1

    I think the rectangles could be useless at this point.

    Could you name the pictures when inserting like this: Picture 1, Picture 2 etc please ?

    Hope its more clear ?

    Thanks
    Last edited by Programmer24; 01-29-2022 at 09:45 AM.

  16. #16
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    See how far this will get you. Change references where required.
    Please Login or Register  to view this content.

    You can hardcode the height and width and leave the InputBoxes out if you want of course.
    I'll have a look at the rest later on when I have some more time.

  17. #17
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    I came up with that myself and it works perfectly. However, I would like to know if you could make it more compact ? + I want to be able to add the picture regardless of its extension


    Please Login or Register  to view this content.

    Then, I woud like to have this code but instead of rectangles I want it to delete all the added pictures if necessary :

    Please Login or Register  to view this content.
    That should be way more clear now he he !

  18. #18
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Tried it with .jpg, .bmp and .gif type pictures. Worked as required.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    I see that in your code in Post #17 you use "select" a few times.
    The use of select is very seldom required and it slows down your macro. You also need to get rid of the screen flicker with Application.ScreenUpdating = False/True

  19. #19
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Very nice !

    I only have noticed one little detail.

    Lets say you have this data in row A :

    1
    2
    3
    4
    5

    Normally, as the code run, it will associate the cell value with the picture and insert it like this

    1 → print picture with name 1.(extension) in cell B41
    2 → print picture with name 2.(extension) in cell B69
    3 → print picture with name 3.(extension) in cell B97
    4 → print picture with name 4.(extension) in cell B125
    5 → print picture with name 5.(extension) in cell B153

    Lets say the picture 3 is not found in the folder, instead of skipping it completely like this :

    1 → print picture with name 1.(extension) in cell B41
    2 → print picture with name 2.(extension) in cell B69
    3 → "Leave blank cell B97 and resume next"
    4 → print picture with name 4.(extension) in cell B125
    5 → print picture with name 5.(extension) in cell B153

    It does that :

    1 → print picture with name 1.(extension) in cell B41
    2 → print picture with name 2.(extension) in cell B69
    4 → print picture with name 4.(extension) in cell B97
    5 → print picture with name 5.(extension) in cell B125

    And its not supposed to !

    Other than that everything seems perfect !

    Waiting for ur feedback.

    And thx btw for the advices and making the code more compact
    Last edited by Programmer24; 01-29-2022 at 11:23 PM.

  20. #20
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    yes, that is on purpose.

    Move the "j = j + k" after the "End If"

  21. #21
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Well thank you very much for your time and expertise!!!

    You are the best !

    Much appreciation from your fellow Canadian

    Have a good one !

  22. #22
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Thank you for your kind words.
    Good Luck and thanks for letting us know that all is well now.

  23. #23
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Hello ! Its me again ! I know... :P

    Mhmm when I insert the pictures, sometimes, some of them are not inserted where they were assigned to and when I click on them, they are either rotated upside down or 90 degrees right or -90 degrees left. Also, when they are rotated, they are shifted lets say 5-6 rows to the right most of the time.

    Is there a way to prevent that ?

    When we used the rectangles it never happenend, but its way better now without them. That is the only problem I encountered.

    To know : When I open the picture in the folder, everything is normal the picture is not rotated but its when I import it in Excel that it rotates.

    The only way I found to correct that is to go in the folder, open the picture, rotate it on time and then put it back to normal and its now good. But when you have 100 pictures its long and anoying.

    Can you help me ?

  24. #24
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Have the pictures been rotated previously and saved?
    Open a few of the culprits in another program, like Irfanview, which is free and a darn good program, and save in proper format.
    If you import them into excel, has anything changed?
    BTW, Irfan view has a bulk setting somewhere where you can manipulate many pictures at once I think.

    https://docs.microsoft.com/en-us/off...emode-property

  25. #25
    Registered User
    Join Date
    11-25-2021
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Works well with Irfan, just tried it out ! Thanks !

  26. #26
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Finding specific picture in a specific folder and insert it somewhere specific

    Thanks for letting us know.
    Good luck

+ 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. Copy 2 specific Sheets, specified range, paste as values to a specific folder
    By wherdzik in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2021, 08:35 AM
  2. [SOLVED] Finding specific amount at specific date for specific person
    By Roshan.Shakya in forum Excel General
    Replies: 3
    Last Post: 05-13-2019, 11:48 AM
  3. Insert Picture from a Folder to Excel if it meets specific content
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2017, 06:17 PM
  4. How to get picture from a specific folder
    By roofi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-10-2013, 07:32 AM
  5. Extract specific column data from specific sheet from multiple files in a folder
    By piggyfox in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-31-2013, 11:51 AM
  6. Creating macro to insert a picture by including specific picture name & path
    By NissaFrenchRamsteyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2012, 05:40 AM
  7. Replies: 9
    Last Post: 05-22-2011, 09:26 AM

Tags for this Thread

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