1

I am trying to write a table of contents at the begining of my powerpoint presentation.

The code I have fetches all the slide that have a title, and print them along with their index.

I would like to know where can I find the command to determine wether or not a slide is hidden. I have searched the msdn VBA Powerpoint section, but came up empty.

For example, my current project is :

For y = 3 To ActivePresentation.Slides.Count
Set Diapo = ActivePresentation.Slides(y)
'si la diapo a un titre
If Diapo.Shapes.HasTitle Then
Set titre = Diapo.Shapes.Title
texte_ajout = texte_ajout & Format(y, "0 - ") & titre.TextFrame. _
TextRange.Text & Chr(13) & vbCrLf
End If
Next y

It counts all of the slides, including those that might be hidden.

I would like (if it is possible) to write this before the first if and after the set Diapo

If Diapo.SlideShowTransition.Hidden = msoTrue Then
Set counthidden = counthidden + 1

...

texte_ajout = texte_ajout & Format(y-counthidden, "0 - ") & titre.TextFrame. _
TextRange.Text & Chr(13) & vbCrLf
End If

(I defined counthidden as byte first, then as long, but it's not working) Is it possible?

R3uK
  • 14,417
  • 7
  • 43
  • 77
Amandine FAURILLOU
  • 528
  • 1
  • 8
  • 23

1 Answers1

2

Here you go ;)

For y = 3 To ActivePresentation.Slides.Count
    Set Diapo = ActivePresentation.Slides(y)
    If Diapo.SlideShowTransition.Hidden = msoTrue Then 'other value : msoFalse
        CountHidden = CountHidden + 1
    Else
        'The slide is not hidden
        If Diapo.Shapes.HasTitle Then
            'si la diapo a un titre
            Set titre = Diapo.Shapes.Title
            texte_ajout = texte_ajout & Format(y - CountHidden, "0 - ") & titre.TextFrame. _
                TextRange.Text & Chr(13) & vbCrLf
        End If
    End If
Next y
R3uK
  • 14,417
  • 7
  • 43
  • 77
  • Thanks that's exactly the function I was looking for. Do you know if I can count those hidden slides and substract that number to the slide count dynamically? (I edited the question, I get a "object not defined" error) – Amandine FAURILLOU Sep 30 '15 at 11:50
  • Don't use the `Set` keyword, it's only use for Object variables, so String, Long, Boolean, ... won't work with it! It'll work with Shapes, Workbook, Worksheet, ... And when you say subtract to the slide count, do you mean Slides.Count property? Because that, you can't do : `Property Count As Long, Read Only` – R3uK Sep 30 '15 at 12:14
  • Without the set keyword,it works better. For the substract part, i mean the value of y, not the presentation properties. For instance, if i have a hidden slide at index 8 and a titled slide at 9, i want the titled slide to appear in ToC with the number 8. – Amandine FAURILLOU Sep 30 '15 at 12:30
  • 1
    I would say yes, if you use something like this `Format(y - counthidden, "0 - ")`. And btw, I'm glad you post this because I thought a long time ago to build something like this, but I didn't think that the `HasTitle` in `Shapes` would mean that the slide has a title or not! :) – R3uK Sep 30 '15 at 12:36
  • Yep, that'll do. It is perfect! Do you know if it is possible to generate a powerpoint presentation automatically, replacing placeholder with their values in an excel sheet? I have the question prepared to be sent, but I dont have internet on my desktop. – Amandine FAURILLOU Sep 30 '15 at 12:40
  • Yes, it is most probably possible, but I don't have the full structure in mind, but the idea is to add a new slide for each line in excel and use slide's templates (layout in VBA if I remember well and then I think you can do the heavy lifting with what you already have, the fine tunes maybe worth a question afterwards). If you post the question, poke me here so I'll know ;) – R3uK Sep 30 '15 at 12:56
  • I meant in a way of keywords inside slides. I already have the layout of the presentation. The slide are set, the content of them is what I want changed. – Amandine FAURILLOU Sep 30 '15 at 13:10
  • I don't exactly know how to do this but if you seek a bit, I think it is possible but you'll have to prepare the data properly to place it in the way you want with VBA. Let me know if you post the question, I'll try to help you ;) – R3uK Sep 30 '15 at 13:14
  • 1
    I have finally internet again, and posted the question : http://stackoverflow.com/questions/32867412/generating-a-powerpoint-presentation-with-vba-and-excel – Amandine FAURILLOU Sep 30 '15 at 13:30