VBA 用于大写标题幻灯片
VBA for capitalizing title slides
我想使用 VBA 将我所有 PowerPoint 幻灯片标题中的每个单词大写。
到目前为止,这是我正在使用的代码:
Sub Capitalize()
Dim sld As Slide
For Each sld In ActivePresentation.Slides
sld.Title.TextFrame.TextRange.ChangeCase ppCaseTitle
Next sld
End Sub
通过突出显示 "Title" 并说 "Method or data member not found"
给我一个错误
如有任何帮助,我们将不胜感激。谢谢!
A Slide
object 没有 Title
属性。您需要查找包含标题文本的 Shape
object。
迭代 .Shapes
collection 并使用它的 Name
知道何时找到包含您的标题的那个(然后您可以退出循环)。
假设您已将标题形状命名为 "Title" 或其他名称。
Dim sld As Slide, shp As Shape
Dim found As Boolean
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.Name = "Title" Then
found = True
shp.TextFrame.TextRange.ChangeCase ppCaseTitle
End If
If found Then Exit For
Next
If found Then Exit For
Next
标题 object 在形状 object 上可用,它映射到幻灯片的占位符标题。我还会使用 HasTitle 属性 检查幻灯片是否有标题。
Sub Capitalize()
Dim sld As Slide
For Each sld In ActivePresentation.Slides
If sld.Shapes.HasTitle Then
sld.Shapes.Title.TextFrame.TextRange.ChangeCase ppCaseTitle
End If
Next sld
End Sub
我想使用 VBA 将我所有 PowerPoint 幻灯片标题中的每个单词大写。
到目前为止,这是我正在使用的代码:
Sub Capitalize()
Dim sld As Slide
For Each sld In ActivePresentation.Slides
sld.Title.TextFrame.TextRange.ChangeCase ppCaseTitle
Next sld
End Sub
通过突出显示 "Title" 并说 "Method or data member not found"
给我一个错误如有任何帮助,我们将不胜感激。谢谢!
A Slide
object 没有 Title
属性。您需要查找包含标题文本的 Shape
object。
迭代 .Shapes
collection 并使用它的 Name
知道何时找到包含您的标题的那个(然后您可以退出循环)。
假设您已将标题形状命名为 "Title" 或其他名称。
Dim sld As Slide, shp As Shape
Dim found As Boolean
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.Name = "Title" Then
found = True
shp.TextFrame.TextRange.ChangeCase ppCaseTitle
End If
If found Then Exit For
Next
If found Then Exit For
Next
标题 object 在形状 object 上可用,它映射到幻灯片的占位符标题。我还会使用 HasTitle 属性 检查幻灯片是否有标题。
Sub Capitalize()
Dim sld As Slide
For Each sld In ActivePresentation.Slides
If sld.Shapes.HasTitle Then
sld.Shapes.Title.TextFrame.TextRange.ChangeCase ppCaseTitle
End If
Next sld
End Sub