Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Set objPresentation = objPPT.Presentations.Open("C:\Scripts\Test.ppt")
Set colSlides = objPresentation.Slides
For Each objSlide in colSlides
objSlide.NotesPage.Shapes(2).TextFrame.TextRange = ""
Next
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:
Set colSlides = objPresentation.Slides
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:
objSlide.NotesPage.Shapes(2).TextFrame.TextRange = ""
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:
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Scripts'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
If objFile.Extension = "ppt" Then
Set objPresentation = objPPT.Presentations.Open(objFile.Name)
Set colSlides = objPresentation.Slides
For Each objSlide in colSlides
objSlide.NotesPage.Shapes(2).TextFrame.TextRange = ""
Next
objPresentation.Save
objPresentation.Close
End If
Next
objPPT.Quit
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:
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Set objPresentation = objPPT.Presentations.Open("C:\Scripts\Test.ppt")
Set colSlides = objPresentation.Slides
For Each objSlide in colSlides
Wscript.Echo objSlide.Shapes(1).TextFrame.TextRange
Wscript.Echo objSlide.NotesPage.Shapes(2).TextFrame.TextRange
Wscript.Echo
Next
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!
0 comments:
Post a Comment