Consulting

Results 1 to 2 of 2

Thread: Insert the different picture into all worksheets

  1. #1
    VBAX Regular
    Joined
    Sep 2013
    Posts
    10
    Location

    Insert the different picture into all worksheets

    hi all...

    how to inserting different 3 pictures in different cell and different sheets ( i have 50 sheets)
    Sub InsertPic()    Dim I As Long
        Dim xPath As String
        Dim xShape As Shape
        Dim xRg As Range
        xPath = "G:\foto_test\1.jpg,2.jpg,3.jpg"
        If Dir(xPath) = "" Then
            MsgBox "Picture file was not found in path!", vbInformation, "test"
            Exit Sub
        End If
        For I = 1 To ActiveWorkbook.Sheets.Count
            Set xRg = Sheets(I).Range("B10:C10") ("D10:E10") (f10:g10)
            Set xShape = Sheets(I).Shapes.AddPicture(xPath, True, True, xRg.Left, xRg.Top, xRg.Width, xRg.Height)
        Next End Sub
    file name picture is always 1.jpg, 2.jpg,3.jpg

    my target is
    1.jpg----inserted into cell B10:C10 for each sheet ( i have 50 sheet)
    2.jpg----inserted into cell D10:E10 for each sheet ( i have 50 sheet)
    3.jpg----inserted into cell F10:G10 for each sheet ( i have 50 sheet)

    anybody help greatly appreciated

    ssanto.
    Attached Files Attached Files

  2. #2
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    My thought is to auto-generate the image name as a text string, and place this routine in a loop.

    this could then read
    'xpath = "G:\foto test" & sString'
    the loop could be something like

    for myNum = 1 to 50 step 3
       sString = myNum & ".jpg, " & myNum+1 & ".jpg " & myNum+2 & ".jpg
    next mynum
    Remember: it is the second mouse that gets the cheese.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •