Reputation: 23
Very basic question : I'm currently trying to get an action button to copy to clipboard a given text. At the moment, It's working with :
Sub CopyPasteButton()
With ActivePresentation.Slides(1)
.Shapes(5).TextFrame.TextRange.Copy
End With
End Sub
ActivePresentation.Slides(1) being the slide number in which I'm looking for the macro to work, and .Shapes(5) the fifth shape of the page in which is contained the text. Problem is I'm duplicating this sub for each slide on which I'd want this function to work, and I have a lot of slides. Also, when I add a slide, everything has to be manually re-written in the module.
I'm willing to get on single macro that would work for every slide, I was thinking of using this tiny bit of code I found on the web, but can't wrap my noob head around it :
Dim diapo As Slide
Set diapo = ActiveWindow.Selection.SlideRange(1)
Upvotes: 1
Views: 1115
Reputation: 41
Assuming that your target shape is always the 5th one. you can create a shape and assign this macro. you can copy and paste the shape to any slide.
Sub CopyPasteButton()
Dim sld As Slide
Dim shp As Shape
'current slide where your button is
Set sld = ActivePresentation.SlideShowWindow.View.Slide
'assuming that your target shape is always the 5th one
Set shp = sld.Shapes(5).TextFrame.TextRange.Copy
End Sub
Though, I would suggest that you give your target shape/text a name in the selection pane. It would be much easier and your code should look like this:
Sub CopyPasteButton()
Dim sld As Slide
Dim shp As Shape
'current slide where your button is
Set sld = ActivePresentation.SlideShowWindow.View.Slide
'If you have a specific name for your target
Set shp = sld.Shapes("NameOfYourShape").TextFrame.TextRange.Copy
End Sub
Hope this helps
Upvotes: 1