VSTO Add-In to automatically export custom PowerPoint slide shows
One of the groups in my company works on a very large PowerPoint slide deck. Not all of the slides in this deck are relevant to everyone. The purpose of this deck is to have a singular source of material which people can pick and choose slides depending the type of presentation that is needed. The slide deck has a number of pre-defined custom slide shows to make this process easier.
While this solution works well in many cases, we need a simple way to quickly export a Custom Show to a new presentation. I'm aiming to develop a VSTO add-in that will allow a user to select one or more custom slide shows and then export the slide s开发者_开发知识库hows to their desktop and I'm looking for some code to help get me on my way.
Does anyone know how to export an existing Custom Show to a new presentation? Better yet, is there a way to allow users to select and export one or more existing shows?
Great question, I've wanted to do this myself for a long time, so took the time to figure it out for you (and me!).
Basically, you'll want to a) loop through all NamedSlideShows
, b) find their slides by SlideID
, c) add a new presentation and then d) copy over the NamedSlideShow
slides with the original design. You can do this for one or all Custom Shows, based on how you send in the commands.
Here's an example:
Sub FindShows()
Dim p As PowerPoint.Presentation
Set p = PowerPoint.ActivePresenation
Dim cShow As PowerPoint.NamedSlideShow
For Each cShow In p.SlideShowSettings.NamedSlideShows
SaveCustomShow (cShow.Name, p)
'If using PowerPoint 2010 use the following line instead:
'SaveCustomShow cShow.Name, p
Next
End Sub
The FindShows
sub just finds all Custom Shows in the ActivePresentation
and sends them to a routine that will create the each new presenation based on the specified Custom Show name. You can customize this as needed.
This routine below is the heart of it. There are a couple of things to note:
- To send over the slide design of the source slide, you have to explicity set the copied slide to use that design.
- A
NamedSlideShow
will only give you theSlideID
of the slides within it. You can useFindBySlideID
to then identify that slide in the original presentation - it returns a slide object. Then you simply copy it and paste it with the design of the original.
Sub SaveCustomShow(showName As String, p As Presentation)
Dim cShows As PowerPoint.NamedSlideShows
Set cShows = p.SlideShowSettings.NamedSlideShows
Dim cSlideIDs As Variant
cSlideIDs = cShows(showName).SlideIDs
Dim destinationPath As String
destinationPath = "C:\Temp\"
Dim newP As PowerPoint.Presentation
Set newP = PowerPoint.Presentations.Add(WithWindow:=False)
With newP
.SaveAs destinationPath & cShows(showName).Name
Dim s As PowerPoint.Slide
Dim e As Integer
For e = 1 To UBound(cSlideIDs)
Set s = p.Slides.FindBySlideID(SlideID:=cSlideIDs(e))
s.Copy
.Slides.Paste.Design = s.Design
Next
.Save
.Close
End With
Set newP = Nothing
End Sub
There's not any error checking in the code, so that will need to be worked out, but it works like a charm!
This works a treat! careful to create a copy of the file first!
http://www.pptfaq.com/FAQ00893.htm
精彩评论