VBA : Number the slide if they are visible

两盒软妹~` 提交于 2020-01-15 10:06:25

问题


I have a powerpoint presentation with hidden slides.

I want to number only the visible slides.

I got this code :

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

I got this error :

Execution Error : '-2147188160 (80048240)':
HeaderFooter (unknown member) : Invalid request

I don't understand why vba doesn't recognise the HeaderFooter member (here is what MSDN says)

Can you help me figure out what seems to be wrong?


回答1:


The MSDN example, as is so often the case, is half-accurate at best. If the Footer object isn't visible, attempting to assign text to it results in the error you're seeing. Here's a slight mod to your code that works:

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


来源:https://stackoverflow.com/questions/35266264/vba-number-the-slide-if-they-are-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!