Insert complete photo dialog using code only

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Insert complete photo dialog using code only

Post by ABabeNChrist »

I know how to insert a single photo or to use CTRL + A to select all the photos from photo dialog. But is there a way to do this with one piece of code.

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert complete photo dialog using code only

Post by HansV »

Do you mean that you want to insert all pictures from a folder?
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Insert complete photo dialog using code only

Post by ABabeNChrist »

yes from a selected folder

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert complete photo dialog using code only

Post by HansV »

You'll have to modify the following code to suit your needs.

Code: Select all

Sub InsertPictures()
    Dim sFolder As String
    Dim sFile As String
    Dim i As Long
    Dim w As Worksheet
    With Application.FileDialog(4) ' msoFileDialogFolderPicker
        If .Show Then
            sFolder = .SelectedItems(1) & Application.PathSeparator
        Else
            Beep
            Exit Sub
        End If
    End With
    Set w = ActiveSheet ' or a specific sheet
    sFile = Dir(sFolder & "*.jpg")
    Do While sFile <> ""
        i = i + 1
        w.Shapes.AddPicture Filename:=sFolder & sFile, _
            LinktoFile:=False, SaveWithDocument:=True, _
            Left:=72 * i, Top:=72 * i, _
            Width:=400, Height:=300
        sFile = Dir
    Loop
End Sub
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Insert complete photo dialog using code only

Post by ABabeNChrist »

Thank you Hans