如何引用幻灯片母版的占位符

发布于 2025-01-09 14:21:11 字数 1744 浏览 0 评论 0原文

我正在尝试获取幻灯片母版 文本占位符 2 中主占位符的尺寸 - 在代码中将是“MasterPlaceholder” - (其尺寸已被修改,并且仅拉动新尺寸在第三个布局中,如图所示)并将它们设置为调整其他布局中所有其他占位符大小的基础。给定标题占位符和正文/通用占位符之间的一定距离,我想循环所有布局并应用新大小。

但是,我不知道如何指向这个形状,我尝试了几种方法(还有“ActivePresentation.Designs(1).SlideMaster.Shapes.Placeholders.(“Text Placeholder 2”)”、“ActivePresentation.Designs(1)”。 SlideMaster.Shapes.Placeholders.Name("Text Placeholder 2")",但我找不到一种没有错误的方法来指向它。

有人可以让我知道如何正确引用吗这也将帮助我找到一种引用“PlcHlder”的方法,这将是要调整的形状

在此处输入图像描述

Sub PlaceHolderResizer()
Dim LeftLimit As Single
Dim TopLimit As Single
Dim RightLimit As Single
Dim BottomLimit As Single
Dim DrawingAreaWidth As Single
Dim DrawingAreaHeight As Single
Dim MasterPlaceholder As Shape
Dim PlcHldr As Shape
Dim oShape As Shape
Dim HorizontalDistance As Single
Dim VerticalDistance As Single
Dim HeadingToPlaceholder As Single


HorizontalDistance = 360
VerticalDistance = 144
HeadingToPlaceholder = 144



Set MasterPlaceholder = SlideMaster.Shapes.Placeholders.Name("Text Placeholder 2")




     LeftLimit = MasterPlaceholder.Left
     TopLimit = MasterPlaceholder.Top
     RightLimit = MasterPlaceholder.Left + oShape.Width
     BottomLimit = MasterPlaceholder.Top + oShape.Height
     DrawingAreaWidth = MasterPlaceholder.Width
     DrawingAreaHeight = MasterPlaceholder.Height



For Each oShape In ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4).Shapes



    If oShape.Name = "Content Placeholder 2" Then
    
        oShape = PlcHldr
        oShape.Left = LeftLimit
        oShape.Width = (DrawingAreaWidth / 2) - HorizontalDistance
    End If
Next oShape


End Sub

I am trying to get the dimensions of the main placeholder in the Slide Master Text placeholder 2 - that in the code would be "MasterPlaceholder" - (whose size has been modified, and the new dimensions are pulled only in the third Layout, as shown in the picture) and set them as the basis for the resizing of all other placeholders in the other Layouts. Given a certain distance between Heading's placeholders and Body/Generic placeholders, I would like to loop through all Layouts and apply the new size.

However, I do not know how to point to this shape and I tried several ways (also "ActivePresentation.Designs(1).SlideMaster.Shapes.Placeholders.("Text Placeholder 2")", "ActivePresentation.Designs(1).SlideMaster.Shapes.Placeholders.Name("Text Placeholder 2")", but I cannot find a way to point it without errors.

Could someone please let me know how to properly refer to it? This would also help me find a way to refer to "PlcHlder", which would be the shape to be ridimensioned

enter image description here

Sub PlaceHolderResizer()
Dim LeftLimit As Single
Dim TopLimit As Single
Dim RightLimit As Single
Dim BottomLimit As Single
Dim DrawingAreaWidth As Single
Dim DrawingAreaHeight As Single
Dim MasterPlaceholder As Shape
Dim PlcHldr As Shape
Dim oShape As Shape
Dim HorizontalDistance As Single
Dim VerticalDistance As Single
Dim HeadingToPlaceholder As Single


HorizontalDistance = 360
VerticalDistance = 144
HeadingToPlaceholder = 144



Set MasterPlaceholder = SlideMaster.Shapes.Placeholders.Name("Text Placeholder 2")




     LeftLimit = MasterPlaceholder.Left
     TopLimit = MasterPlaceholder.Top
     RightLimit = MasterPlaceholder.Left + oShape.Width
     BottomLimit = MasterPlaceholder.Top + oShape.Height
     DrawingAreaWidth = MasterPlaceholder.Width
     DrawingAreaHeight = MasterPlaceholder.Height



For Each oShape In ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4).Shapes



    If oShape.Name = "Content Placeholder 2" Then
    
        oShape = PlcHldr
        oShape.Left = LeftLimit
        oShape.Width = (DrawingAreaWidth / 2) - HorizontalDistance
    End If
Next oShape


End Sub

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

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

发布评论

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

评论(2

囍孤女 2025-01-16 14:21:11

幻灯片母版上只能有一个文本占位符。因此,您可以使用占位符 Type 属性来识别它并获取其名称:

Sub GetPlaceHolderName()
    Dim oShape As Shape
    
    For Each oShape In ActivePresentation.SlideMaster.Shapes
        If oShape.PlaceholderFormat.Type = ppPlaceholderBody Then
            MsgBox oShape.Name
        End If
    Next oShape
End Sub

循环遍历对象集合以获取名称是 PowerPoint VBA 课程的标准内容,您将经常使用该技术。

On the slide master, there can only be one text placeholder. So you can use the placeholder Type property to identify it and get its name:

Sub GetPlaceHolderName()
    Dim oShape As Shape
    
    For Each oShape In ActivePresentation.SlideMaster.Shapes
        If oShape.PlaceholderFormat.Type = ppPlaceholderBody Then
            MsgBox oShape.Name
        End If
    Next oShape
End Sub

Looping through object collections to get names is par for the course with PowerPoint VBA, you'll use that technique very often.

水水月牙 2025-01-16 14:21:11

https://learn.microsoft.com/en- us/office/vba/api/powerpoint.placeholders,我将索引 2分配给形状(因为有一个标题,这将是1),最后占位符被重新-尺寸(此时的大小并不重要,因为这是我稍后会修复的问题)。该代码仍然需要很大的改进,但至少我在我所指的项目中看到了一些操作。

我必须找到一种方法以某种方式通过名称指向占位符,这比索引号更健谈。

Sub PlaceHolderResizer()
Dim LeftLimit As Single
Dim TopLimit As Single
Dim RightLimit As Single
Dim BottomLimit As Single
Dim DrawingAreaWidth As Single
Dim DrawingAreaHeight As Single
Dim MasterPlaceholder As Shape
'Dim PlcHldr As Shape
Dim oShape As Shape
Dim HorizontalDistance As Single
Dim VerticalDistance As Single
Dim HeadingToPlaceholder As Single


HorizontalDistance = 72
VerticalDistance = 144
HeadingToPlaceholder = 144



Set MasterPlaceholder = ActivePresentation.SlideMaster.Shapes.Placeholders(2) ' here is how I should have called it




     LeftLimit = MasterPlaceholder.Left
     TopLimit = MasterPlaceholder.Top
'     RightLimit = MasterPlaceholder.Left + oShape.Width
'     BottomLimit = MasterPlaceholder.Top + oShape.Height
     DrawingAreaWidth = MasterPlaceholder.Width
     DrawingAreaHeight = MasterPlaceholder.Height



For Each oShape In ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4).Shapes



    If oShape.Name = "Content Placeholder 2" Then
    
'        oShape = PlcHldr
        oShape.Left = LeftLimit
        oShape.Width = DrawingAreaWidth - HorizontalDistance
    End If
Next oShape


End Sub

As in https://learn.microsoft.com/en-us/office/vba/api/powerpoint.placeholders, I assigned the Index 2 to the shape (because there is a title, which would be 1) and finally the placeholder was re-dimensioned (the size at this moment does not matter, since it is something I will fix later). The code still needs great improvement, but at least I saw some action in the item I was referring to.

I will have to find a way to point to the placeholder by name somehow, something more talkative than an index number.

Sub PlaceHolderResizer()
Dim LeftLimit As Single
Dim TopLimit As Single
Dim RightLimit As Single
Dim BottomLimit As Single
Dim DrawingAreaWidth As Single
Dim DrawingAreaHeight As Single
Dim MasterPlaceholder As Shape
'Dim PlcHldr As Shape
Dim oShape As Shape
Dim HorizontalDistance As Single
Dim VerticalDistance As Single
Dim HeadingToPlaceholder As Single


HorizontalDistance = 72
VerticalDistance = 144
HeadingToPlaceholder = 144



Set MasterPlaceholder = ActivePresentation.SlideMaster.Shapes.Placeholders(2) ' here is how I should have called it




     LeftLimit = MasterPlaceholder.Left
     TopLimit = MasterPlaceholder.Top
'     RightLimit = MasterPlaceholder.Left + oShape.Width
'     BottomLimit = MasterPlaceholder.Top + oShape.Height
     DrawingAreaWidth = MasterPlaceholder.Width
     DrawingAreaHeight = MasterPlaceholder.Height



For Each oShape In ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4).Shapes



    If oShape.Name = "Content Placeholder 2" Then
    
'        oShape = PlcHldr
        oShape.Left = LeftLimit
        oShape.Width = DrawingAreaWidth - HorizontalDistance
    End If
Next oShape


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