我在Powerpoint中创建了一个宏,它将搜索使用文本框作为标题的幻灯片,并用标题框替换它们。步骤是
1)找到标题区域中有文本框的幻灯片
2)将文本框中的文本复制到名为slTitle的变量中
3)删除texbox
4)为当前幻灯片创建标题持有者
5)将文本复制到标题持有人中
6)转到下一张幻灯片
我的宏目前能够进入第4步,但我无法弄清楚如何将slTitle
中的文本放入标题框中。这应该是相当容易的,但我已经尝试了几种方法,似乎没有任何工作。如果有人能帮助我弄清楚这一步,我将不胜感激。
我收到编译错误“无效限定词”:
Set ppPlaceholderTitle.TextFrame.TextRange.Text = slTitle
这是我当前的宏。
Sub AddMiMissingTitles()
Dim shpCurrShape As Object
Dim x As Integer
Dim sl As PowerPoint.Slide
Dim sld As Slide
Dim ctr As Integer
Dim s As Shape
'x = ActivePresentation.Slides.Count
'counter ctr used to count number of slides that needed titles added
ctr = 0
'**************************************************************
Set sourcePres = ActivePresentation
x = 1 ' slide counter
'get the title text
For Each sl In sourcePres.Slides
'delete all the empty title text boxes first
For Each s In sl.Shapes
If s.Top < 45 Then ' it's in the title area
'MsgBox s.PlaceholderFormat.Type
If s.Type <> ppPlaceholderTitle Then ' it isn't a proper Title placeholder
If s.HasTextFrame = msoTrue Then
If Trim(s.TextFrame.TextRange.Text) = "" Then
s.Delete ' delete empty text holders
Else
slTitle = s.TextFrame.TextRange.Text
s.Delete
sl.CustomLayout = sl.CustomLayout 'reset the slide
Set ppPlaceholderTitle.TextFrame.TextRange.Text = slTitle
End If
End If
End If
End If
Next
'Is there a title placeholder on the current layout?
If sl.CustomLayout.Shapes.HasTitle Then
lngType = sl.CustomLayout.Shapes.Title.PlaceholderFormat.Type
'*********************************
' With ActivePresentation.Slides()
End If
Next
MsgBox "Done! " & vbCrLf & ctr & " Slides needed Titles."
'*********************************
'sl.Shapes.AddPlaceholder lngType
sl.Shapes.Title.TextFrame.TextRange = slTitle
End Sub