4

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?

Amandine FAURILLOU
  • 528
  • 1
  • 8
  • 23

1 Answers1

7

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
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • Hi, can I do the same thing, but using .SlideNumber instead of .Footer so that the numbers are displayed on the bottom right? – Amandine FAURILLOU Feb 11 '16 at 10:05
  • Have you tried it? Did it work? If not, what didn't work? – Steve Rindsberg Feb 12 '16 at 20:14
  • I tried, it did not want want anything but the actual slide numbers to be displayed (counting the hidden ones), it flat out refused to write anything in the .slideNumber. – Amandine FAURILLOU Feb 13 '16 at 00:15
  • I suspect you'll need to add text boxes to the slides where you want the numbers to appear rather than relying on slide number placehoders (which will always display the slide's index number rather than an arbitrary number based on how many slides are hidden or not) – Steve Rindsberg Feb 13 '16 at 02:20
  • I still have exactly the same error: `HeaderFooter (unknown member) : Invalid request` and I have it still at this line: `diapo.HeadersFooters.Footer.Text = CStr(x)` It seems that it is not able to assign text to the `Footer` object. Can you help me to solve this problem? – desmond13 May 03 '23 at 06:43
  • I think I found my problem and it is related to the template I use. Indeed, if I go in Slide Master View I see that I am not able to tick the `Footers` thickbox. I tried the VBA code in another blank presentation and worked flawlessly. – desmond13 May 03 '23 at 06:49