none
Help with Inserting Pictures from URL in Excel, RRS feed

  • Question

  • Tried to make a macro that progressively inserts 3 images in Excel

    One worksheet (pics) contains the URLs of images in Column A row 1-3

    The other worksheet (outputs) is supposed to output the images horizontally.

    Sub testinsertpix()
    Dim i As Integer
    Dim link As String
    
    For i = 1 To 3
    link = Worksheets("pics").Cells(i, "A").Value
    Cells(1, i).Select
    ActiveSheet.Pictures.Insert (link)
    
    Next i
    
    End Sub
    

    It does insert the first image, but fails when the loop reaches the 2nd picture.

    "Insert method of Pictures class failed"

    Little help please?

    Thursday, May 16, 2013 7:44 AM

All replies

  • Does this work better?

    Sub testinsertpix()
        Dim i As Integer
        Dim link As String
        Dim cel As Range
        With Worksheets("Output")
            For i = 1 To 3
                link = Worksheets("pics").Cells(i, "A").Value
                Set cel = .Cells(1, i)
                .Shapes.AddPicture Filename:=link, LinktoFile:=False, _
                    SaveWithDocument:=True, Left:=cel.Left, _
                    Top:=cel.Top, Width:=cel.Width, Height:=cel.Height
            Next i
        End With
    End Sub

    (I used the AddPicture method of the Shapes collection instead of the Insert method of the hidden Pictures collection)

    Regards, Hans Vogelaar

    Thursday, May 16, 2013 8:11 AM