NaturalTvven
08-08-2014, 01:43 PM
Greetings,
I am attempting my first marco in powerpoint. I am simply trying to copy a 'reference' slide and replace one picture. I will do this for all pictures in a folder. The script I have adds all the slides, but then adds all the pictures to the final slide. I don't understand why this is the case since the Duplicate Slide code and the Add Picture code are in the same while loop. Can someone tell me why?
Sub LoopThroughFiles()
Dim StrFile As String
Dim Folder As String
Dim sld As Slide
Dim referencesld As Slide
Set referencesld = ActivePresentation.Slides(1)
Dim i As Integer
Dim shp As Shape
i = 1
Folder = "c:\E1B8\ScriptTesting\MISC\PPT\SampleData2\"
StrFile = Dir(Folder & "*")
Set referencesld = ActivePresentation.Slides(1)
Set shp = referencesld.Shapes(5)
Do While Len(StrFile) > 0
Debug.Print Folder & StrFile
referencesld.Duplicate
i = i + 1
Set sld = ActivePresentation.Slides(i)
With shp
sld.Shapes.AddPicture(Folder & StrFile, msoFalse, msoTrue, .Left, .Top, .Width, .Height).IncrementRotation 360#
End With
sld.Shapes(5).Delete
StrFile = Dir
Loop
End Sub
Thanks!!
I am attempting my first marco in powerpoint. I am simply trying to copy a 'reference' slide and replace one picture. I will do this for all pictures in a folder. The script I have adds all the slides, but then adds all the pictures to the final slide. I don't understand why this is the case since the Duplicate Slide code and the Add Picture code are in the same while loop. Can someone tell me why?
Sub LoopThroughFiles()
Dim StrFile As String
Dim Folder As String
Dim sld As Slide
Dim referencesld As Slide
Set referencesld = ActivePresentation.Slides(1)
Dim i As Integer
Dim shp As Shape
i = 1
Folder = "c:\E1B8\ScriptTesting\MISC\PPT\SampleData2\"
StrFile = Dir(Folder & "*")
Set referencesld = ActivePresentation.Slides(1)
Set shp = referencesld.Shapes(5)
Do While Len(StrFile) > 0
Debug.Print Folder & StrFile
referencesld.Duplicate
i = i + 1
Set sld = ActivePresentation.Slides(i)
With shp
sld.Shapes.AddPicture(Folder & StrFile, msoFalse, msoTrue, .Left, .Top, .Width, .Height).IncrementRotation 360#
End With
sld.Shapes(5).Delete
StrFile = Dir
Loop
End Sub
Thanks!!