Log in

View Full Version : macro for placing images from folder/directory



JoJo3436
03-30-2016, 05:36 AM
Hello,

I'am trying to create a macro in powerpoint that does the following: it opens a file dialog to a predefined location. Then the user can select a picture and place it in the presentation. I am pretty new to vba so any help is welcome.

Joost

hunter21188
03-31-2016, 05:57 PM
Add this to a module (just input your desired file location):


Sub InsBckg()


Dim osld As Slide
Dim oFD As FileDialog
Dim sFile As String
Dim opic As Shape
Dim sFolder As String
Set osld = ActiveWindow.View.Slide
Set oFD = Application.FileDialog(msoFileDialogFilePicker)
sFolder = "INSERT FILE LOCATION HERE"
With oFD
.InitialFileName = sFolder
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Pictures", "*.JPG, *.PNG ,*.BMP"
If .Show = msoTrue Then sFile = .SelectedItems(1)
End With
If sFile <> "" Then
Set opic = osld.Shapes.AddPicture(FileName:=sFile, _
Top:=0, _
Left:=0, _
Height:=True, _
Width:=True, _
LinKToFile:=False, _
SaveWithDocument:=True)
End If


End Sub


Then just run that.

I think that should do what you want.

John Wilson
04-03-2016, 11:17 AM
It will and the code looks familiar!
http://answers.microsoft.com/en-us/office/forum/office_2007-powerpoint/how-do-i-create-a-vb-script-to-insert-pictures/b4cefe29-8e46-4200-bfee-e8403522ab41?msgId=1431f10b-1fa6-44f1-b449-2384f0620eb2