非常基本的问题:我目前正在尝试获取一个操作按钮,以将给定的文本复制到剪贴板。目前,它正在使用:
Sub CopyPasteButton()
With ActivePresentation.Slides(1)
.Shapes(5).TextFrame.TextRange.Copy
End With
End Sub
ActivePresentation.Slides(1)是我要在其中运行宏的幻灯片编号,而.Shapes(5)是其中包含文本的页面的第五种形状。问题是我要为要在上面运行此功能的每张幻灯片复制此子项,并且我有很多幻灯片。另外,当我添加一张幻灯片时,所有内容都必须在模块中手动重写。
我愿意使用适用于每张幻灯片的单个宏,我正在考虑使用我在网络上找到的一小段代码,但无法将菜鸟头包起来:
Dim diapo As Slide
Set diapo = ActiveWindow.Selection.SlideRange(1)
假设您的目标形状始终是第5个形状。您可以创建形状并分配此宏。您可以将形状复制并粘贴到任何幻灯片。
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
尽管,我建议您在选择窗格中为目标形状/文本命名。这样会容易得多,您的代码应如下所示:
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
希望这会有所帮助