![用于复制命令按钮的 VBA 代码](https://linux22.com/image/1362240/%E7%94%A8%E4%BA%8E%E5%A4%8D%E5%88%B6%E5%91%BD%E4%BB%A4%E6%8C%89%E9%92%AE%E7%9A%84%20VBA%20%E4%BB%A3%E7%A0%81.png)
我被难住了。请帮忙。什么 VBA 代码可用于将命令按钮从一张幻灯片复制到另一张幻灯片(以及它们背后的代码)?我想我可以处理循环,但我找不到执行实际复制的代码/行/命令。谢谢!
答案1
下面是一个 VBA 宏,用于将所有按钮从一张幻灯片复制到另一张幻灯片:
Option Explicit
Public Sub copyButtons(sourceSlide As Slide, targetSlide As Slide)
Dim shp As Shape
If sourceSlide.Name <> targetSlide.Name Then
For Each shp In sourceSlide.Shapes
If InStr(shp.Name, "Button") > 0 Then
shp.Copy
targetSlide.Shapes.Paste
End If
Next shp
End If
End Sub
Public Sub testCopyButtons()
Dim sourceSlide As Slide
Dim targetSlide As Slide
Set sourceSlide = ActivePresentation.Slides(2)
Set targetSlide = ActivePresentation.Slides(3)
Call copyButtons(sourceSlide, targetSlide)
End Sub
复制的按钮将继承原始按钮的链接和操作。