使用VBA代码从自定义模板中应用特定布局

发布于 2025-02-01 04:51:13 字数 831 浏览 2 评论 0原文

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).

Click here for the image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心舞飞扬 2025-02-08 04:51:13

此线程存在相同的问题,此答案主要是重述那里已经显示的内容。

例如,如果您知道您的自定义布局“内容页面”的索引始终是3,那么您可以这样进行此操作:

With ActivePresentation
    .Slides.AddSlide _
        Index:=.Slides.Count + 1, _ 
        pCustomLayout:=.Designs(1).SlideMaster.CustomLayouts(3)
End With

如果您不确定您的自定义布局将始终具有相同的索引,那么您' 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:

With ActivePresentation
    .Slides.AddSlide _
        Index:=.Slides.Count + 1, _ 
        pCustomLayout:=.Designs(1).SlideMaster.CustomLayouts(3)
End With

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文