Microsoft Office 2000/Visual Basic Programmer's Guide |
There are two ways you can create a PowerPoint presentation:
Dim ppApp As PowerPoint.Application
Dim prsPres As PowerPoint.Presentation
Set ppApp = New PowerPoint.Application
With ppApp
Set prsPres = .Presentations.Add(msoFalse)
With prsPres
' Code here to add and format slides in
' the new presentation.
End With
End With
Note The WithWindow argument of the Add and Open methods accepts a Boolean value that specifies whether the Window object that contains the presentation will be visible. (The default is True.) Although the Auto List Members drop-down list for the Add method's WithWindow argument contains five enumerated constants, you should use only the msoTrue or msoFalse constants.
When you use VBA to create a new presentation, it exists in memory but will not be saved to disk until you use the Presentation object's SaveAs method. (Use the Save method to save changes to a presentation that has already been saved to disk.) The following procedure creates a new Presentation object and immediately saves the presentation by using the name supplied in the strPresName argument. It then returns the new Presentation object to the calling procedure.
Function PPTCreatePresentation(ppApp As PowerPoint.Application, _
strPresName As String) As PowerPoint.Presentation
' This procedure illustrates how to use the SaveAs method to
' save a new presentation as soon as it is created.
' Note that in this example, the new Presentation object
' is not visible.
On Error GoTo PPTCreate_Err
Set PPTCreatePresentation = ppApp.Presentations.Add(msoFalse)
If InStr(strPresName, "\") = 0 Then
strPresName = "c:\" & strPresName
End If
PPTCreatePresentation.SaveAs strPresName
PPTCreate_End:
Exit Function
PPTCreate_Err:
Select Case Err
Case Err <> 0
Set PPTCreatePresentation = Nothing
End Select
Resume PPTCreate_End:
End Function
The PPTCreatePresentation procedure is available in the modPPTCode module in PowerPointTools.ppt in the ODETools\V9\Samples\OPG\Samples\CH05 subfolder on the Office 2000 Developer CD-ROM.