+ Reply to Thread
Results 1 to 4 of 4

inserting images into different excel sheets using their names

  1. #1
    Registered User
    Join Date
    09-08-2021
    Location
    France
    MS-Off Ver
    2017
    Posts
    2

    inserting images into different excel sheets using their names

    Hello I am a real beginner on VBA.
    I have a workbook on which I managed to create copies of an example sheet and rename the new sheets according to a list.

    But now I would like to integrate an image with the same name as the sheet to each newly created sheet. The last step would be to ignore if a sheet has no image related but first i need to figure out what i am doing wrong on this part.

    Thanks for the help

    PHP Code: 
    Sub JPG()
    Dim i As Long
    Dim Image 
    As String
    Dim Name 
    As String
    Dim Way 
    As String

    Image 
    ".jpg"
    Way "C:\Picture\"

        For i = 1 To ActiveWorkbook.Sheets.Count
            Sheets(i).Shapes.AddPicture _
                Filename:=Way & Sheets(i).Name & Image,
                linktofile:=msoFalse, savewithdocument:=msoCTrue, _
            Left:=20, Top:=20, Width:=140, Height:=140
        Next i
    End Sub 

  2. #2
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: inserting images into different excel sheets using their names

    Maybe it is because this line
    Please Login or Register  to view this content.
    should be like this ?
    Please Login or Register  to view this content.
    to continue the loop if there is no image name in the folder with the same name of the sheet,
    maybe try to put "on error resume next" line just before the "for i =" line
    Last edited by karmapala; 09-10-2021 at 01:44 AM.

  3. #3
    Registered User
    Join Date
    09-08-2021
    Location
    France
    MS-Off Ver
    2017
    Posts
    2

    Re: inserting images into different excel sheets using their names

    **** me,
    I forgot this "_", I'm really so unfamiliar with the coding language that I didn't see this oversight.

    I also added the line you suggested and it seems to work, it ignores the sheets that don't have an image

    Here is the final code, if you have any other advice I'd love to hear it.

    And thanks for the help it saved me.

    PHP Code: 
    Sub JPG()
    Dim i As Long
    Dim Image 
    As String
    Dim Name 
    As String
    Dim Way 
    As String

    Image 
    ".jpg"
    Way "C:\Picture\"
    On Error Resume Next
        For i = 1 To ActiveWorkbook.Sheets.Count
            Sheets(i).Shapes.AddPicture _
                Filename:=Way & Sheets(i).Name & Image, _
                linktofile:=msoFalse, savewithdocument:=msoCTrue, _
            Left:=20, Top:=20, Width:=140, Height:=140
        Next i
    End Sub 

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

    Re: inserting images into different excel sheets using their names

    Pretty close to what you have.
    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)

Similar Threads

  1. [SOLVED] Inserting images based on an Excel list of items
    By Antiriad2097 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-06-2013, 01:08 PM
  2. [SOLVED] Inserting Images into Excel
    By JungleJme in forum Excel General
    Replies: 1
    Last Post: 06-08-2012, 10:21 AM
  3. Excel 2007 : Inserting multiple images
    By Mickmac in forum Excel General
    Replies: 0
    Last Post: 03-08-2011, 05:14 AM
  4. inserting images (jpg) into cells in Excel 2007
    By dpacifico in forum Excel General
    Replies: 1
    Last Post: 03-24-2010, 04:52 AM
  5. inserting images in excel automatically
    By leonachs49 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2009, 08:51 PM
  6. Inserting linked images into Excel 2003 worksheet
    By ferrell in forum Excel General
    Replies: 1
    Last Post: 04-19-2007, 09:29 PM
  7. [SOLVED] Problem inserting images in VBA forms in Excel on a Mac
    By Bernadette in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2006, 02:15 AM
  8. [SOLVED] Inserting images into excel conditionally
    By Pav in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-16-2005, 06:00 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