+ Reply to Thread
Results 1 to 16 of 16

VBA to insert picture

  1. #1
    Registered User
    Join Date
    03-24-2011
    Location
    Lancashire
    MS-Off Ver
    Excel 2007
    Posts
    54

    VBA to insert picture

    Hello all,

    I'm looking for some help please.

    I am trying to get the code to loop through each row on the "front page" sheet, get a picture name, look in the chosen directory & if found then insert it in another sheet.

    Sheet names are based off the values in column 1, so as the code looks for the picture name in the first row (starting at row 4) column 19, it will then look for that worksheet name based on the value in column 1 (starting at row 4), go to that sheet and paste the picture at F26, then go to the next row until it gets to the end of the rows. I'm not that clued up on VBA and this is what I have ended up with, however it doesn't work! I get no errors, but no picture either.

    Would any of you be willing to help at all?

    Please Login or Register  to view this content.

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

    Re: VBA to insert picture

    Re: "look in the chosen directory"
    How is this happening? Is this hard coded in the code?
    Are all pictures guaranteed to be in that folder or could there be pictures missing?
    Are the sheets all there or do these have to be added?
    If the sheets exist, do they need to be cleared?
    Last edited by jolivanes; 10-27-2019 at 09:00 PM. Reason: More info requested

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA to insert picture

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

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

    Re: VBA to insert picture

    It is assumed that:
    All pictures in range exist in folder.
    All sheets exist in workbook and are not hidden or have protection.
    That the picture names are full names (have the extension)
    That the range with picture names and sheet names are in a sheet named "front page" (Exaxt spelling without double quotation marks.)

    Please Login or Register  to view this content.
    Good evening (morning for you) Rudi. You're too fast for me again.
    Last edited by jolivanes; 10-27-2019 at 09:50 PM. Reason: Hello to bakerman

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA to insert picture

    Hi right back to you, jolivanes. It's 3 a.m. here and on my way to put the bread in the oven.

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

    Re: VBA to insert picture

    Hmmmm, lekker. Een vers broodje met kaas!

    "It's 3 a.m. here". Reminds me of my working days!!!!
    Last edited by jolivanes; 10-27-2019 at 10:20 PM.

  7. #7
    Registered User
    Join Date
    03-24-2011
    Location
    Lancashire
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: VBA to insert picture

    Hi Bakerman2 / Jolivanes

    Thanks for the help.

    I tried both the codes and they do as required. However, sometimes they wont always have a picture name in the column & I have noticed that if one line is empty, it breaks the code. Is there anyway we can get this to either, insert "no photo found" for the blank cells or no file name that matches the column data and/or skip that row if no picture name is present?

    Regards

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

    Re: VBA to insert picture

    Change this part
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-24-2011
    Location
    Lancashire
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: VBA to insert picture

    Jolivanes,

    I tried the change but I get a "Run-time error '1004' Unable to get the Insert property of the Picture class" at
    Please Login or Register  to view this content.
    Also, how would I change the size of the screenshot with your code?

    Thanks Jolivanes

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

    Re: VBA to insert picture

    Read the first 5 lines of Post #4 again. Also make sure there are values in Column A where there are Values in Column S (=19).
    If all else fails, attach your Workbook without data we don't need to know (names, addresses and whatever).

    Try changing this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA to insert picture

    This one only kicks in when Sheetname and picturename are present in columns1 and cloumns19.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-30-2019
    Location
    Kabul, Afghanistan
    MS-Off Ver
    2016
    Posts
    2

    Re: VBA to Lookup picture from a folder

    Hello all

    i need help!

    i have a work book which contained employee details like (ID, Name, Poistion, etc)
    i have another sheet as main page in the workbook in which i pull an employee all detail by entering ID number by Index and Match formula, but what i need when i put ID of employee in main page his photo should be also previewed.

    i should mention that i have all employees photos in a folder in my D drive, employee photo is renamed by employee's ID number. the photos should be looked-up from that folder. (need VBA code and guidance)

    help please !!!
    thanks
    Last edited by b.amarkhail; 11-30-2019 at 02:13 AM.

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

    Re: VBA to Lookup picture from a folder

    @ b.amarkhail
    Please start your own thread.

  14. #14
    Registered User
    Join Date
    11-30-2019
    Location
    Kabul, Afghanistan
    MS-Off Ver
    2016
    Posts
    2

    Re: VBA to Lookup picture from a folder

    Hi Jolivanes

    thanks for reply;

    i am new to this forum; i did not understand what do you mean by start my own thread;
    please if you make it more clear, i am not professional in English.
    thanks

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    Restart by reading first the forum rules …

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

    Re: VBA to insert picture

    Just think for a minute. If everybody did the same as you, there would be just ONE thread with thousands of different problems. How would you ever find anything at all.
    What you did is called hijacking because you take over someone else's thread. That's why you need to start your own with a proper heading and a clear explanation of what you want.
    It looks like it would be advantageous to attach a workbook with a before and after scenario. No personal info like real names, real addresses etc etc.

+ 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. [SOLVED] Insert picture on blank colored cells and remove all picture
    By Anisusa in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 06-07-2018, 10:19 AM
  2. [SOLVED] Modify VBA to insert picture embedded in file instead of a link to a picture
    By edthedrummer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2017, 02:12 AM
  3. [SOLVED] insert picture the same size and location of existing picture
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2015, 11:14 AM
  4. VB code to insert picture when email picture not in excel
    By T_BOLT in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2014, 06:42 AM
  5. VBA for Picture insert at particular worksheet range. Picture name derived from cell.
    By Douglas2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2013, 01:16 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. [SOLVED] macro: insert picture based on workbook location, not picture root path.
    By NicksDad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2012, 07:47 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