PPT2000: How to use the Presentations.Open MethodID: q222758
|
This article describes how to use the Microsoft Visual Basic for Applications Presentations.Open method. The Open method opens an existing Microsoft PowerPoint presentation.
Microsoft provides programming examples for illustration only, without
warranty either expressed or implied, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft Support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to
provide added functionality or construct procedures to meet your specific
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspNOTE: The following macro examples only work from within the PowerPoint application. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, please see the following article in the Microsoft Knowledge Base:
Q230746 PPT: Viewer: Presentation Macros Don't Run
Name |
DataType |
Required |
FileName |
String |
Yes |
ReadOnly |
|
Optional |
Untitled |
Long |
Optional |
WithWindow |
Long |
Optional |
Sub OpenPresentation()
Presentations.Open "c:\test.ppt"
End Sub
Sub OpenPresentationReadOnly()
Presentations.Open "c:\test.ppt", msoTrue
End Sub
[test.ppt[Read-Only]]If you do not specify the msoTrue parameter, it is set to msoFalse (the default), and the presentation opens as Read/Write.
Sub OpenCopy()
Presentations.Open "c:\test.ppt", Untitled:=msoTrue
End Sub
[test.ppt]
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:=msoTrue
is 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
starting with the statement that 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 quits. When a run-time error occurs, information about that error is
stored in the Err object.
For more information about using the sample code in this article, please
see the following article in the Microsoft Knowledge Base:
Q212536 OFF2000: How to Run Sample Code from Knowledge Base Articles
Additional query words: 9.00 ppt9 vba vbe ppt2k powerpt vba2k ppt9.0 ppt2000 program programming
Keywords : kbcode kbmacro kbprg kbdta kbdtacode kbpptvba
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 14, 1999