Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I need to write a PowerPoint VB macro to paste the same image on all my slides (inserting it on the Master slide does not work as it remains in the background and gets overlaid with large pictures in the foreground).

I have found (and adapted) the following snippet:

VB
Sub SuperDuper()
    Dim x As Long

    For x = 1 To ActivePresentation.Slides.Count
        ActivePresentation.Slides(x).Shapes.Paste
    Next

End Sub


it does execute the Paste operation, but the pasting location changes from slide to slide. How can I fix this ?
Posted

I have used this code:
VB
ActiveWindow.View.Paste
ActiveWindow.Selection.ShapeRange(1).Name = shapeName
With NewPres.Slides(SlideNumber).Shapes(shapeName)
    .Height = gridHeight
    .Width = gridWidth
    .Left = gridLeft
    .Top = gridTop
    .ZOrder gridZOrder
End With


After it pastes it is still selected so you can then give it a name and reference it that way and set it's various properties.
 
Share this answer
 
Comments
YvesDaoust 7-Oct-13 10:57am    
Thanks for the suggestion
ZurdoDev 7-Oct-13 11:10am    
No problem.
YvesDaoust 7-Oct-13 11:22am    
I assume (not tested) that you can do without naming the shape:
With ActiveWindow.Selection.ShapeRange(1)
...
End With
ZurdoDev 7-Oct-13 11:30am    
Likely. I was using it more in the code later so I did, but yes, I believe that would also work.
Here is my final, cleaned-up script. Very simple once you know the recipe:
VB
Sub PasteToAll()
    For i = 1 To ActivePresentation.Slides.Count
        Set MyRange = ActivePresentation.Slides(i).Shapes.Paste
        MyRange(1).Left = 100
        MyRange(1).Top = 100
    Next
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900