Excel VBA Insert images from image name in column

I read a lot, if there are different threads about inserting images and recalibrating them, but they can’t find one that does exactly what I want it to do.

So to speak, I have a table with two rows. Column A, which is the image column, and column B, which is the image name.

I want to have a script that will go through each value in column B, insert the image corresponding to this name in the same row on column A, resize it to fit a cell size that is 150 by 18, then go to the next line and repeat it through the spreadsheet.

-4
source share
1 answer

, (B1: B100), , (, A), B.

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("B7:B7")
For Each cl In rng
    pic = cl.Offset(0, -1)

        Set myPicture = ActiveSheet.Pictures.Insert(pic)
        '
        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

, , , .

+4

Source: https://habr.com/ru/post/1694841/


All Articles