Hey, Scripting Guy! How Can I Remove the Speaker Notes From a PowerPoint Presentation?

Hey, Scripting Guy! Question

Hey, Scripting Guy! We have a whole bunch of PowerPoint presentations that we would like to share with other people. However, before we make these presentations available we’d like to remove all the speaker notes from each one. Is there a way we can use a script to remove the speaker notes from a PowerPoint presentation?
— TW

Spacer Hey, Scripting Guy! Answer Script Center

Hey, TW. Before we begin, we’d like to welcome all of you to the 935thHey, Scripting Guy! column. This is an incredible and exciting milestone for us and – what’s that? Why are making such a big deal about the 935th column? Why don’t we at least wait until the 1000th column? After all, at a rate of one column a day, that’s not that far off.

You know what? That’s a fair enough question. As it turns out, though, 935 is a very special, almost-mystical number in many cultures throughout the world. Which cultures throughout the world? Well, we don’t have time to list them all. But we’re pretty sure there are a lot of them. In fact, we’re pretty sure that there are many such cultures.

Or at least there has to be one such culture somewhere, right?

True story. The Scripting Guys were once told that a number of teams had complained that the Scripting Guys were extremely difficult to work with. “Really?” said the Scripting Guys. “Can you name one of these teams?” “No,” came the reply. “But that doesn’t matter. There’s just a whole bunch of them and that’s all there is to it.”

And, to be honest, that’s probably true. Although we seem to get along just fine with real teams, we definitely have our problems with make-believe teams. No doubt these teams are upset that we’ve taken our own make-believe, cartoon-like character – Scripting Guy Peter Costantini – and tried to pass him off as though he was a real person.

At any rate, welcome again to the 935thHey, Scripting Guy! column. As a way to mark the occasion we originally planned to give away brand-new Lamborghini Murcielagos to the first 935 people who read the column. After we checked the current price of gas, however, we were afraid that our winners might not be all that excited with their prize: according to the U.S. Environmental Protection Agency, the Murcielago gets 8 miles per gallon. The EPA further estimates that it would take 2.5 gallons of gas to drive the Murcielago 25 miles. Based on the current price of gas in the Seattle area, that means it would cost you $11.25 to drive 25 miles. Need to make a 2,600 mile trip from Seattle to San Diego and back? Hey, no problem: that’ll run you $1,170.

Or you could fly roundtrip for $286. It’s up to you.

That’s about the time we decided to forego the Lamborghini Murcielagos and substitute the next best thing: a script that can remove all the speaker notes from a Microsoft PowerPoint presentation. Please note that we didn’t have enough money in our budget to mail individual copies of the script to the first 935 people who read this column. If you’re one of the first 935, congratulations: you’re a winner! If you’re not one of the first 935, well, we hope you’ll do the right thing and not read this column. After all, fair is fair, right?

At any rate, here’s the script. Congratulations again to all our winners:

So how does this chunk of code actually work? Well, to begin with, we create an instance of the PowerPoint.Application object and then set the Visible property to True; that gives us a running instance of PowerPoint that we can see on screen. The moment we have our instance of PowerPoint in hand we use the Open method to open the presentation C:\Scripts\Test.ppt, then use this line of code to retrieve a collection of all the slides in that presentation:

And then we stop to catch our breath for a moment. Whew!

Fortunately it’s all downhill from here. To begin with, we set up a For Each loop to loop through each slide in the collection. For each of those slides all we do is execute the following line of code:

And you’re right: that is a crazy-looking line of code, isn’t it? Why is it so crazy-looking? Well, as it turns out, each slide has a NotesPage object that contains the speaker notes; the second shape on the NotesPage is a TextFrame object where the notes actually reside. To delete the notes for a given slide we simply need to set the value of the TextFrame’s TextRange property to an empty string.

Wow; now we really need to stop to catch our breath.

Fortunately, though, we’re pretty much done here; all we have to do now is – wait a minute: are you sure you’re one of the first 935 people to read this column? Well, OK; we have to take your word for it. Anyway, all we have to do now is go back to the top of the loop and repeat the process with the next slide in the presentation. And then we go back and do it all over a third time, and then a fourth time, continuing along these same lines until we’ve removed the notes from each and every slide in the presentation.

Now, what if you wanted to do this for all the .PPT files in a folder? Well, that’s easy; all you have to do is run this script:

And because someone is bound to ask, what if you did need a script that could echo back the speaker notes for an entire presentation? No problem. The following script opens the file Test.ppt and retrieves a collection consisting of all the slides in that presentation. For each slide the script echoes back the slide title (objSlide.Shapes(1).TextFrame.TextRange) and the speaker notes:

That should do it, TW; we hope you find this script useful, and we hope you enjoyed the 935thHey, Scripting Guy! column. We should level with you, however: believe it or not, there really isn’t any significance to the number 935. (Although 935 was the year when Haakon the Good, son of Harald Fairhair, reunited the Norwegian lands.) The truth is, we decided to celebrate column 935 for one reason and one reason only: when you’re a Scripting Guy, you never know when a given column might be your last. See you all tomorrow!

Well, probably.


No Comment.