Article ID: 162555
Article Last Modified on 10/11/2006
Name Data Type Required ---- --------- -------- FileName String Yes ReadOnly Long Optional Untitled Long Optional WithWindow Long OptionalFileName:
The FileName parameter is the path and name of the presentation you wish to open. The following Visual Basic example opens a file named test.ppt located in the C:\ root directory.
Sub OpenPresentation()
Presentations.Open "c:\test.ppt"
End Sub
The ReadOnly parameter is used to open a presentation as Read-Only. The following example opens a file named test.ppt as Read-Only.
Sub OpenPresentationReadOnly()
Presentations.Open "c:\test.ppt", msoTrue
End Sub
The parameter, msoTrue, tells PowerPoint to open the presentation
ReadOnly. When test.ppt is open, the following text appears in the title
bar:
[test.ppt[Read-Only]]
The Untitled parameter is used to create a copy of the presentation. The following example opens a copy of test.ppt.
Sub OpenCopy()
Presentations.Open "c:\test.ppt", Untitled:=msoTrue
End Sub
If you do not specify the msoTrue parameter, it is set to msoFalse (the
default), and the file name only appears in the title bar:
[test.ppt]
The WithWindow parameter open a presentation without making it visible. The following example opens test.ppt, does not show it, and then closes it.
Sub OpenInvisible()
Dim MyPres As Presentation
Set MyPres = Presentations.Open("c:\test.ppt", _
WithWindow:=msoFalse)
' Close the presentation.
MyPres.Close
End Sub
NOTE: When you are finished with the invisible presentation, make sure
you close the presentation.
Presentations.Open "c:\test.ppt", WithWindow:=msoTrueis equivalent to this code example:
Presentations.Open "c:\test.ppt"
Sub GetReturnValue()
Dim MyPres As Presentation
Set MyPres = Presentations.Open("c:\test.ppt")
' This counts the number of slides in test.ppt.
MsgBox MyPres.Slides.Count
End Sub
NOTE: To use the return value of a method, set the method to a variable and
enclose the parameters in parentheses.
Sub ErrorTrapOpen()
On Error Resume Next
' Clear all values in the Err object.
Err.Clear
Dim MyPres As Presentation
Set MyPres = Presentations.Open("c:\file does not exist.ppt")
' If error occurred when opening the file, display the error message.
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "Error " & Err.Number
End If
End Sub
The On Error Resume Next statement allows the macro to continue to execute
beginning with the statement that immediately follows the statement that
generated the error. If you do not use the On Error Resume Next statement,
you will receive a run-time error if the file cannot be opened and the
macro halts. When a run-time error occurs, information about that error is
stored in the Err object.
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 97 8.00 kbmacro kbpptvba ppt8 vba vbe 8.0 kbhowto
Keywords: kbcode kbdtacode kbhowto kbmacro kbprogramming KB162555