我有一个代码可以将对象从幻灯片粘贴到活动幻灯片。我该如何使代码粘贴到母版中?
Public Function AddShapeBooktitle()
Dim s As String, p As Presentation, o As Shape
'open the file and copy the object
If CommandBars.ActionControl.Parameter <> "" Then
s = Ini.GetResourcePath & CG_ADDIN_NAME & "\" & CG_INSERT_FOLDER & CG_BOOKTITLE_FOLDER & CommandBars.ActionControl.Parameter
Set p = Presentations.Open(s, ReadOnly:=True, WithWindow:=msoFalse)
p.Slides(1).Shapes.Range().Copy
p.Close
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
Else
MsgBox "The Shape file name is missing.", vbExclamation, "Shape file name missing."
End If
End Function
感谢任何专业帮助!谢谢!
答案 0 :(得分:0)
您需要确定当前幻灯片的自定义布局,然后将形状粘贴到SlideMaster中的适当布局中。这样的事情在单个演示文稿中起作用。如果您在可能具有不同SlideMaster
集合的多个演示文稿之间进行工作,则可能需要以某种方式调整逻辑。但这是一般的想法:您需要确定SlideMaster.CustomLayouts
的哪个将是Paste
操作的目的地。
Option Explicit
Sub foo()
Dim p As Presentation
Dim sld As Slide
Dim layout As CustomLayout
Set p = ActivePresentation
Set sld = p.Slides(1)
layout = sld.CustomLayout.Index
sld.Shapes.Range().Copy
p.SlideMaster.CustomLayouts(layout).Shapes.Paste
End Sub