我有一个带有隐藏幻灯片的 Powerpoint 演示文稿。
我只想对可见的幻灯片进行编号。
我得到这个代码:
Sub Numerotation()
Dim x As Integer
Dim diapo As Slide
For Each diapo In ActivePresentation.Slides
If diapo.SlideShowTransition.Hidden = False Then
x = x + 1
diapo.HeadersFooters.Footer.Text = x
Else
diapo.HeadersFooters.Footer.Text = ""
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Execution Error : '-2147188160 (80048240)':
HeaderFooter (unknown member) : Invalid request
Run Code Online (Sandbox Code Playgroud)
我不明白为什么vba不能识别HeaderFooter成员(这是MSDN所说的)
你能帮我找出哪里出了问题吗?
MSDN 的例子,就像经常发生的那样,充其量只是一半准确。如果页脚对象不可见,尝试为其分配文本会导致您看到的错误。这是对您的代码进行的一个小的修改,可以正常工作:
Sub Numerotation()
Dim x As Integer
Dim diapo As Slide
For Each diapo In ActivePresentation.Slides
If diapo.SlideShowTransition.Hidden = False Then
x = x + 1
diapo.HeadersFooters.Footer.Visible = True
diapo.HeadersFooters.Footer.Text = CStr(x)
Else
diapo.HeadersFooters.Footer.Visible = False
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)