PPT =使用节名称

时间:2018-12-28 17:29:22

标签: powerpoint-vba

是否有一种方法可以在(每张)幻灯片的文本框中显示部分名称,以便可以将其传达给查看者? 如图所示: https://answers.microsoft.com/en-us/msoffice/forum/all/ppt-using-section-names-in-footer/2b844798-2afa-4216-9ba5-5d066ac4dcca 但是我无法使用页脚,因为它已在其他地方使用。

编辑:@ Steve Rindsberg-非常感谢您的回答。
(对不起,很抱歉。我是VBA的初学者(两个星期以来-但是很多小时...)。
这是我的代码:首先,我尝试了以下操作:
我将一个文本框作为占位符添加到SlideMaster.CustomLayout中,文本为“ Section#”。

Sub AddTextboxToSlidemaster()
Dim shp As Shape
On Error Resume Next
Set shp = Application.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1).Shapes.AddPlaceholder(ppPlaceholderObject,  _
Left:=223.75, Top:=9#, Width:=453.62, Height:=12.18898)
With shp
    shp.Tags.Add "TEXT", "Section#"  'this seems to be unnecessary
       With .TextFrame
            .TextRange.Text = "Section#"
       With .TextRange
                .Font.Size = 12
                .Font.name = "Verdana"
                .Font.Color.RGB = RGB(7, 37, 62)
                .ParagraphFormat.Bullet = msoFalse
           End With
       End With
    End With
End Sub  

然后,我将此占位符/文本框复制到一些相关的自定义布局中。 接下来,我添加了一些带有这些自定义布局之一的幻灯片(在slideView中)。所以我在一些幻灯片上有这个占位符/文本框。

下一步:我在所有幻灯片中搜索文本“ Section#”,并用标签“ TEXT”,值“ Section#”标记这些占位符:

Sub FindTextSelectionAndTag()
For Each sld In Application.ActivePresentation.Slides
    For Each shp In sld.Shapes
        If shp.HasTextFrame Then
            Set txtRng = shp.TextFrame.TextRange
            Set foundText = txtRng.Find(FindWhat:="Section#")
            Do While Not (foundText Is Nothing)
                With foundText
                shp.Tags.Add "TEXT", "Section#"
        Set foundText = _
                        txtRng.Find(FindWhat:="Section#", _
                        After:=.Start + .Length - 1)
              End With
            Loop
        End If
    Next
Next
End Sub 

但是幻灯片上的占位符不接受该标签。

因此,我改为在一些相关的幻灯片上直接设置带有文本“ Section#”的文本框-如您所建议-然后运行宏以标记文本框:
如上所述的“ Sub FindTextSelectionAndTag()”。

最后,我创建一个宏,它将当前部分带到分类/标记的文本框中。

Sub AbschnittHeader()
  Dim sld As Slide
  Dim shp As Shape
  Dim b_found As Boolean
    If ActivePresentation.SectionProperties.Count > 0 Then
      For Each sld In ActivePresentation.Slides
      For Each shp In sld.Shapes
  If shp.Tags("TEXT") = "Section#" Then _
  shp.TextFrame.TextRange = 
 ActivePresentation.SectionProperties.name(sld.sectionIndex)
     Next shp
   Next sld
 End If
End Sub

到目前为止有效。

我想在该代码中进行可能的优化-我有一个问题,在Masterslide.customlayout上添加占位符有什么问题。有没有办法使这项工作有效-因为我认为这种方式会更舒适。或为此目的做到这一点。

我还想将PowerPoint文件(ActivePresentation)的名称添加到文本框中的部分中,如下所示(但我不知道如何):

PowerPoint文件的名称| sld.sectionIndex

例如(pptFile的名称:Marketing):
市场营销第1章简介
市场营销第二章……

感谢您的建议。

1 个答案:

答案 0 :(得分:0)

非常感谢。现在这是我可以使用的最终解决方案:
如我的问题所述,首先Sub Sub AddTextboxToSlides()-不是母版,而是几张幻灯片-然后是Sub AbschnittHeader()可选,并带有以下几行:

a。包含在文件名中

For Each shp In sld.Shapes
  If shp.Tags("TEXT") = "Section#" Then _
    shp.TextFrame.TextRange = ActivePresentation.FullName _
    & " | " & ActivePresentation.SectionProperties.name(sld.sectionIndex)

b。或包含在第一张幻灯片的“文件标题”中:-)

For Each shp In sld.Shapes
  If shp.Tags("TEXT") = "Section#" Then _
    shp.TextFrame.TextRange = _
    ActivePresentation.Slides(1).Shapes.Title.TextFrame.TextRange.Text _
    & " | " & ActivePresentation.SectionProperties.name(sld.sectionIndex)