PDA

View Full Version : VBA CODE FOR SELECTING PICTURE FROM A SPECIFIC FOLDER



ElCapitano
02-23-2022, 01:43 AM
Hello,guys
You have any ideas why this code doesn't work? Is to put pictures into a word document from a specific folder... Thanks...

Sub GetPictures()
Dim sPic As String
Dim sPath As String

sPath = "c:\myfolder"
sPic = Dir(sPath & "*.jpg")

Do While sPic <> ""
Selection.InlineShapes.AddPicture _
FileName:=sPath & sPic, _
LinkToFile:=False, SaveWithDocument:=True
sPic = Dir
Selection.TypeParagraph
Selection.TypeParagraph
Loop
End Sub

arnelgp
02-23-2022, 02:35 AM
your variable sPath need to have a backslash at the end:

sPath = "c:\myfolder\"

gmayor
02-23-2022, 03:27 AM
You may find https://www.gmayor.com/photo_gallery_template.html useful.

ElCapitano
02-23-2022, 03:37 AM
your variable sPath need to have a backslash at the end:

sPath = "c:\myfolder"

thanks... you have any ideea how can i control where to put the pictures ? what I must change in the code...