Add slide number and total number of slides on every slide in PowerPoint
Adding a current slide number in PowerPoint is a fairly easily task, it involves just a few steps, and it is covered by Microsoft docs. Adding total number of slides sounds like a bigger problem with “Using macros” tiny voice in the background.
First of all, there is an addtional Microsoft doc about adding slide count to each slide as well. But, it orders you to insert a text field and… manually write total number of slides in particular presentation. You have to also keep it updated. This is Microsoft-insane.
Contents
Creating macro
- In PowerPoint 2007 and newer make sure, that you saved your presentation under
.pptm
extension (standard presentation with macros allowed). Make sure, that you have added slide numbers using method described in this article1.
Open “Macro” window2. In PowerPoint 2007 and newer, click on
View
tab (last) and then onMacro
button in last toolbar group. In eariler versions selectTools > Macro
from menu.Type a name for your macro (say
PageCountUpdater
), select where you want to save this macro and clickCreate
.Paste macro code (from pwrpntuser‘s answer or below) between
Sub PageCountUpdater()
andEnd Sub
. Changevan
in the most indented line toof
or anything similar in your lang.Save macro and close Microsoft Visual Basic for Applications.Go back to PowerPoint.
You’re done. Code to be inserted (full and with corrected “glue-word”):
Sub PageCountUpdater() Dim s As Slide Dim shp As Shape For Each s In ActivePresentation.Slides s.DisplayMasterShapes = True s.HeadersFooters.SlideNumber.Visible = msoTrue For Each shp In s.Shapes If Left(shp.Name, 12) = "Slide Number" Then shp.TextFrame.TextRange.Text = " (slajd nr " &s.SlideNumber & " z " & ActivePresentation.Slides.Count & ") " End If Next Next End Sub
Executing macro
- Open “Macro” window again.
Select saved
PageCountUpdater
macro and hitRun
.
You have to do this each time manually. A keyboard shortcut would be most welcome.
Unfortunately, a few jerks at Microsoft figured out one day, that it will be so cool to not let user customize shortcut keys for PowerPoint (you can do this in Word). And they’ve decided to no implement such feature. So, if you want to really add a keyboard shortcut to this newly created macro, you have to pay an insane prices starting at 20 bucks per one computer. See end of this or this article for a details.
Auto-recreated labels
If you manually delete label with slide number (and total number of slide), it will always be recreated once you run this macro again.
There are two ways, how you can deal with this problem.
First, is to remove macro, once you’re done with all edits to particular presentation (i.e. you won’t be adding or deleting any slide) and convert file back to .pptx
, without macros. See next chapter for details.
If you want to remain of macro-enabled files, there’s another nifty workaround to reappearing labels problem. Leave them in their original position, but set their font color to something as close as background color in that place, as possible. Plus set their font size to 1pt. This will make them invisible or very hard to be spotted. But, they’ll still be there, so macro can update them as many times as it want.
Deleting macro
This macro should be only run, when you need it. It is not a live-macro. It updates field with actual slide count and that’s it. Field itself is a standard text field. No magic. This means, that you can easily convert your file back to .pptx
and throw this macro away, once you’re sure, that your presentation is done and you’ll be adding no more slides to it. Field will remain in their places with their values untouched, once macro is removed.
This is comfortable as many users does not like documents with macros and many presentation places, fairs, conferences etc. simply won’t let you run .pptm
file.
My workflow for this was something similar to:
- I finished presentation in meaning, that I was sure, that I’ll be adding or deleting no more slides (changes to text on each slide are of course allowed)/
I run this macro once more to update numbering fields at all slides.
I deleted labels from first and last slide and macro from macro list.
Finally, I converted presentation back to
.pptx
file format.
And I was done. Having pretty numbering with current slide and total number of slides on all slides, I wanted. Without dully, stupid and insane Microsoft suggested method of updating this fields manually.
Opening macro-enabled file
If you decide to keep .pptm
extension and macro inside, you’ll have this document always opened with macros disabled and you’ll have to click Enable macros
each time (if you run on default settings) to enable them. To change this, you have to add folder, in where you store these presentations to the group of trusted folders. Details in [this article](Force macro-enabled documents to not display warning, when opened.txt).
Footnotes
1 In most versions of PowerPoint the meaning title slide is determined not as first slide in presentation, but as any slide styled as title slide. You can see diffreent slide types, when inserting new one. This mean that, if you have no slide styled as title, you’ll have page numbers added to all slides. And opposite — if you used many title slides inside presentation, for example to mark different sections or blocks, you’ll have numbering missing on all of them.
2 All GUI elements’ names are on-the-fly translation from my Polish edition of PowerPoint 2010. In other releases or language editions of PowerPoint they may be slightly different. Adjust accordingly.
This blog article is part of this Super User answer.