+ Reply to Thread
Results 1 to 15 of 15

Insert multiple pictures

  1. #1
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Insert multiple pictures

    Hello
    I need your help.
    I have hundreds of photos to insert into an excel sheet.
    Each photograph is an article. The code of the article is the filename of each photo.
    I need a macro that inserts the picture in column B on the same line of code in this article in column C.
    The cell where the photo has got to be 30x100 (width x height)
    This is my typical excel list


    ScreenHunter_03 Feb. 02 15.23.jpgScreenHunter_04 Feb. 02 15.28.jpg


    Someone help me?

    Patricia

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Insert multiple pictures

    Try this macro

    Please Login or Register  to view this content.
    You will need to size the cells before running this as it fits the image to the cell. Also edit the Source Folder string and check if your images ae .jpg - adjust if not.

    Open the VBA editor Alt F11. Inset a new module (Insert - Module) and paste in the above. Go back to the sheet (Alt F11). Run the macro from the view ribbon.
    Martin

  3. #3
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Insert multiple pictures

    Hello
    Already thank you for answering.
    I did as you said but gave this error ScreenHunter_08 Feb. 02 17.08.jpg

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Insert multiple pictures

    It's possible that there is some sort of mismatch between what you have in the cell in column C and the actual name of the file.

    To check this, I would suggest....

    opening the immediate pane in the VBA editor (Control G)
    Typing in a question mark (?) followed by the string copied from the code SourceFolder & Cells(N, 3) & ".jpg"
    With the cursor on the same line, hit return

    You should get a line which shows what the expression evaluates to. My guess is that this will differ in some way from the path that you were expecting.

    If this is not the case, could you attach a few picture files to a reply so that I can experiment?

  5. #5
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Insert multiple pictures

    Hello
    Sorry for the delay in responding. The company I work for had some problems and the matter remained in the background.
    Annex now the file that I use for stock and want to insert the photos.


    Stock List.jpg
    13542.jpg
    13543.jpg
    13545.jpg
    13544.jpg
    Last edited by PatriciaM; 04-03-2012 at 06:41 AM.

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Insert multiple pictures

    Try this variation

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Insert multiple pictures

    Hello
    Thank you. For now works fine ... now I have a huge task ahead of me.

  8. #8
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Insert multiple pictures

    Hello
    The macro inserts the image. It is possible that the macro create a hyperlink on the image to open the file that caused it?
    Some of the image are very small ... so with one click could open the original image.

    Thank you.

    Patricia

  9. #9
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Insert multiple pictures

    Patricia

    Try this slight modification.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Insert multiple pictures

    Hello
    The macro only entered a photo and gave the error in the line of code you see in the image that I attached
    But the link is inserted

    Patricia


    ScreenHunter_01 Apr. 04 15.45.jpg

  11. #11
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Insert multiple pictures

    Hello
    I almost forgot.
    In the first code you sent I made a change because the macro does not work.
    I inserted a line of code "ON ERROR RESUME NEXT"
    the macro ran perfectly well even though I do not know what I did ...
    The second macro without my line of code gives error.
    With the line enters the picture but not the links.



    PHP Code: 
    Option Explicit


    Sub AddPictures
    ()
    Dim N As Long
    On Error Resume Next
    Const SourceFolder "C:\Users\ESCRITORIO\Desktop\pics\"
    For N = 3 To Cells(Rows.Count, 3).End(xlUp).Row
        Cells(N, 2).Select
        With ActiveSheet.Pictures.Insert(SourceFolder & Cells(N, 3) & "
    .jpg")
            .Top = Rows(N).Top + 2
            .Height = Rows(N).RowHeight - 4
            .Left = Columns(2).Left + 2
        End With
            

    Next N
    End Sub 

  12. #12
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Insert multiple pictures

    It seems to work OK for me. The only thing that I can think of is that you have a filename in your sheet which doesn't exist. It would be worth checking the spelling and looking for leading/trailing spaces.

  13. #13
    Registered User
    Join Date
    09-21-2011
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Insert multiple pictures

    Hello
    Ok ... now I understand what you did ... there is no problem I adapt my way of working with macro ... gives just a little more work than what I was thinking but still your macro will make possible what I want.


    Obrigadoooooooooo (many thank you in Portuguese)

  14. #14
    Registered User
    Join Date
    04-25-2012
    Location
    Lithuania
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Insert multiple pictures

    hello, it's working on 2010 excel?
    as I have error - Run-time error '1004': unable to get the insert property of the pictures class
    thank you!

  15. #15
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Insert multiple pictures

    You could try this variation.

    Please Login or Register  to view this content.

+ 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