VBA Code belongs to a Presentation


VBA Code cannot stand alone. It must be contained inside a Powerpoint Presentation,

or an Excel Spreadsheet or a Word Document or other Office application


Declare a Presentation object variable



We declare a variable named pres that can be assigned to a presentation object (PowerPoint file)

* You do not have to assign the presentation to variable.

* However you will then have to use the full presentation string in your code.

* By using a variable for each open presentation, you only have to use the variable name to refer to a specific presentation.

* As we add Slides and Shapes the references can get very long.

* Using a variable name will greatly simplify your code and is good programming practice.



The Presentations collection contains all open .pptx files.

A Presentation is a .pptx file.

Or any valid powerpoint file, like .pptm, .potm, etc.


pres


Next we SET the variable pres to a specific presentation object (.pptx).

Note that these are all methods of the Presentations collection.


Set the presentation variable to a NEW presentation object


* Add a new presentation (.pptx) to the Presentations collection


This will open a new .pptx file.

The variable pres will be assigned to this new PowerPoint file.

The new file will not have a name until it is saved.



It will be saved as a .pptx because the variable pres was declared as a PowerPoint file.



Set the presentation variable to an EXISTING presentation object and OPEN it.


* Open a new presentation (.pptx) to add to the Presentations collection


This will open an existing .pptx file and assign the presentation variable to the file.



Set the presentation object to an already opened file.

All open PowerPoint files are part of the Presentations collection.

Use any of these commands to specify which open file you want to assign the variable name pres.



Assign (SET) the variable by NAME

(These two statements are identical)

The file extension is optional, since it will be .pptx.

Do not include the path. The file is already open.



Assign (SET) the variable by referencing the ActivePresenation

This will set the presentation variable to the currently selected PowerPoint file.

NOTE: The ActivePresentation can be useful if you use only have one file open.

But you have to be sure that the correct .pptx file is selected.

It is better practice to use the name.



Assign (SET) the variable by referencing the Index number of the .pptx file.

(These two statements are identical)

This will set the presentation variable to the PowerPoint file with an index of 1.

All open PowerPoint files (.pptx) are assigned an index when they are opened.

The index will be a number from 1 to the total number of open PowerPoint files.

NOTE: You cannot rely on knowing the index number of an open PowerPoint file.

Index numbers are assigned automatically as PowerPoint files are opened and closed.

It is best to reference a Presentation by its name.



Saving a presentation

If you use the "Save" option, the presentation will be saved under its existing name.

If the presentation was opened as a new presentation, a "SaveAs" dialog box will be displayed to ask for a file name.














Copyright © 2006-2019, LQSystems,Inc. All rights reserved.