Microsoft Office Tutorials and References
In Depth Information
Which One Is Better?
4.
Declare variables for the file path, the PowerPoint file name, and the file extension. The
reason for the variable extension is that starting with Office version 2007, PowerPoint file
extensions are commonly .pptx or .pptm . Prior to 2007, the extension for PowerPoint files was
simply .ppt .
Dim myPath As String, myFileName As String, myExtension As String
5.
Define the variables for myPath and myFileName :
myPath = “C:\Your\File\Path\”
myFileName = “PowerPointExample1”
6.
Use an If structure to define the extension String variable. Note the Val statement, which
ensures the Office application version is regarded as a number for the logical evaluation of
being less than or equal to version 11, which is Office 2003.
If Val(Application.Version) <= 11 Then
myExtension = “.ppt”
Else
myExtension = “.pptx”
End If
7.
Declare the PowerPoint application object and set it using the CreateObject method for late
binding:
Dim appPPT As Object
Set appPPT = CreateObject(“PowerPoint.Application”)
8.
When opening other applications, don’t forget to make them visible:
appPPT.Visible = True
9.
Compose the Open statement for PowerPoint that combines the myPath , myFileName , and
myExtension variables:
appPPT.Presentations.Open Filename:=myPath & myFileName & myExtension
10.
When completed, the macro will look like this, with comments that have been added to
explain each step:
Sub OpenPowerPoint()
‘Declare variables for path, file name and file extension.
Dim myPath As String, myFileName As String, myExtension As String
‘Define the myPath and myFileName variables.
myPath = “C:\Your\File\Path\”
myFileName = “PowerPointExample1”
‘Using an If structure and depending on the host computer’s Office version,
‘define the extension of the PowerPoint file.
If Val(Application.Version) = 11 Then
myExtension = “.ppt”
Else
myExtension = “.pptx”
End If
Search JabSto ::




Custom Search