Insert Pictures with varying naming convention from a list of a specific length VBA

  • This is my first post please be gentle... I am trying to "import" pictures into an excel sheet.I have data in column B that i am adding at the end of a directory string in A1 and then adding the file extension in B1 to return the image. Formula is: =$A$1&A2&$B$1result is: \\inside\ProductImageLibrary\Images\10061.jpg I am then using this with ActiveSheet.Pictures.insert to insert the picture into my sheet. The issue i have is some of pictures have additional attributes in the file name. i.e. 49451_100.jpg I have tried to solve for this using wildcards and extensive google searching to no avail. Ultimate goal with this code would be to bring back the first file that contains the data. I don't know what the additional attributes will be, but I do know somewhere in the name there will be the data 49451 image files for 49451 are:49451_100.jpg 49451_359.jpg 49451_434.jpg etc etc so far this is the code I have.


    Files

    • get_pics.txt

      (579 Byte, downloaded 38 times, last: )
  • Re: Insert Pictures with varying naming convention from a list of a specific length V


    This code works assuming:
    *The directory is in A1
    *Images Paths are in Column B start at Row 2

    Files

    • get_pics.txt

      (1.87 kB, downloaded 37 times, last: )
  • Re: Insert Pictures with varying naming convention from a list of a specific length V


    How about






    P.S
    I strongly recommend not to use "row" as a variable name since it is a reserved word for VBA.

  • Re: Insert Pictures with varying naming convention from a list of a specific length V


    Thank you very much.


    It's great to get different POV on how to solve this and to also see efficient structure that I can add into my code going forward.


    jindon: Your code is the one I'm going to use. I am going to add a couple more directories to search if there is no file found. Thanks.


    dbrown14: Your code works but because of the number of files in the directory it takes a very long time to execute. Thank you for taking a crack at it. I should have specified the directory is quite large in the number of files on it.


    Krishnakumar: thank you for fixing my post.


    Glad I posted and have graduated from lurking this forum for years to actually participating.


    Donald