Inserting an Online Picture to Excel with VBA

后端 未结 2 1094
庸人自扰
庸人自扰 2020-11-30 14:37

I\'m currently working on a project and need to fill in cells with pictures via URLs. All URLs are in one column, and I\'d like to load the images in an adjacent column. I\'

2条回答
  •  庸人自扰
    2020-11-30 15:02

    This is an almost identical solution that I posted about a month ago:

    Excel VBA Insert Images From Image Name in Column

    Sub InsertPic()
    Dim pic As String 'file path of pic
    Dim myPicture As Picture 'embedded pic
    Dim rng As Range 'range over which we will iterate
    Dim cl As Range 'iterator
    
    Set rng = Range("B1:B7")  '<~~ Modify this range as needed. Assumes image link URL in column A.
    For Each cl In rng
    pic = cl.Offset(0, -1)
    
        Set myPicture = ActiveSheet.Pictures.Insert(pic)
        '
        'you can play with this to manipulate the size & position of the picture.
        ' currently this shrinks the picture to fit inside the cell.
        With myPicture
            .ShapeRange.LockAspectRatio = msoFalse
            .Width = cl.Width
            .Height = cl.Height
            .Top = Rows(cl.Row).Top
            .Left = Columns(cl.Column).Left
        End With
        '
    
     Next
    
     End Sub
    

提交回复
热议问题