Forum Discussion
MrGeekyBro
Nov 03, 2023Copper Contributor
Help with Macro to insert pictures from a folder down an excel column.
Alright folks, I could use some help trying to create a macro that can insert a slew of pictures down a column in Excel based off of the picture file names down another corresponding column. Im tryin...
HansVogelaar
Nov 03, 2023MVP
The file names in your worksheet don't include the extension. I used .png in the code, as in your sample code.
Sub InsertPictures()
' Folder path - MUST end in backslash \
Const strFolder = "C:\Users\javog\Pictures\Diversen\"
Dim strFile As String
Dim rng As Range
Dim cel As Range
Application.ScreenUpdating = False
Set rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
For Each cel In rng
strFile = cel.Value & ".png"
ActiveSheet.Shapes.AddPicture _
Filename:=strFolder & strFile, _
LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=cel.Offset(0, 1).Left, _
Top:=cel.Offset(0, 1).Top, _
Width:=-1, _
Height:=-1
Next cel
Application.ScreenUpdating = True
End Sub