Consulting

Results 1 to 4 of 4

Thread: VBA CODE FOR SELECTING PICTURE FROM A SPECIFIC FOLDER

  1. #1

    Angry VBA CODE FOR SELECTING PICTURE FROM A SPECIFIC FOLDER

    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
    Last edited by Aussiebear; 02-23-2022 at 02:13 AM. Reason: Added code tags to supplied code

  2. #2
    your variable sPath need to have a backslash at the end:

    sPath = "c:\myfolder\"

  3. #3
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    Quote Originally Posted by arnelgp View Post
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •