使用VBA代码从自定义模板中应用特定布局
Sub ImportCharts()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape
strPath = ActivePresentation.Path & "\Images\"
strFileSpec = "*.png"
strTemp = Dir(strPath & strFileSpec)
Do While strTemp <> ""
Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.count + 1, ppLayoutCustom)
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0.45 * 72, _
Top:=0.8 * 72, _
Width:=10.1 * 72, _
Height:=6.25 * 72) '
strTemp = Dir
Loop
End Sub
在循环时,pplayoutcustom添加了第一个自定义布局。但是我想将内容页面布局添加为我的自定义布局(请参阅图像)。
Sub ImportCharts()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape
strPath = ActivePresentation.Path & "\Images\"
strFileSpec = "*.png"
strTemp = Dir(strPath & strFileSpec)
Do While strTemp <> ""
Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.count + 1, ppLayoutCustom)
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0.45 * 72, _
Top:=0.8 * 72, _
Width:=10.1 * 72, _
Height:=6.25 * 72) '
strTemp = Dir
Loop
End Sub
In the Do while loop the ppLayoutCustom adds the first custom layout. But I want to add Content Page layout as my custom layout (Refer image).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此线程存在相同的问题,此答案主要是重述那里已经显示的内容。
例如,如果您知道您的自定义布局“内容页面”的索引始终是3,那么您可以这样进行此操作:
如果您不确定您的自定义布局将始终具有相同的索引,那么您' LL需要首先遍历所有自定义布局,找到所需的索引,然后使用上面的代码。当然,您将用自定义布局的真实索引替换
3
。This thread has the same issue and this answer is mostly restating what has already been shown there.
If you know that the index of your custom layout "Content Page" will always be 3, for example, then you can go about it like this:
If you aren't certain that your custom layout will always have the same index, you'll need to first iterate through all of the custom layouts, find the index of the one you want, and then use the code above. Of course, you would replace the
3
with the true index of your custom layout.