Article ID: 222758 - View products that this article applies to.
This article was previously published under 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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. NOTE: The following macro examples work only in PowerPoint. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
ParametersThere are four parameters that you can use to control the behavior of the Open method:
FileNameThe FileName parameter is the path and name of the presentation that you want to open. The following Visual Basic example opens a file named test.ppt located in the C:\ root directory.
ReadOnlyThe ReadOnly parameter is used to open a presentation as Read-Only. The following example opens a file named test.ppt as Read-Only.
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]]If you do not specify the msoTrue parameter, it is set to msoFalse (the default), and the presentation opens as Read/Write.
UntitledThe Untitled parameter is used to create a copy of the presentation. The following example opens a copy of test.ppt.
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:
WithWindowThe WithWindow parameter open a presentation without making it visible. The following example opens test.ppt, does not show it, and then closes it.
NOTE: When you are finished with the invisible presentation, make sure you close the presentation.
If you do not specify the msoFalse parameter, it is set to msoTrue (the default).
This code example:
is equivalent to this code example:
Using the Return ValueThe Open method returns a reference to a presentation object. Once you have the object reference, you can use it to access methods and properties of the presentation.
NOTE: To use the return value of a method, set the method to a variable and enclose the parameters in parentheses.
Error Trapping the Open MethodThe following sample code demonstrates how you can trap errors that may occur when you use the Open method:
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 the Err object, ask the Microsoft PowerPoint Office Assistant.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/212536/EN-US/ )OFF2000: How to Run Sample Code from Knowledge Base Articles