Create a presentation
To make a new blank presentation in Visual Basic for Applications (VBA), you use the following code:
Application.Presentations.Add
Here is the equivalent in AppleScript:
make new presentation
In Microsoft PowerPoint, you cannot set any properties when you create a presentation using the make new command. Normally in AppleScript, you can specify many or most of the properties of a document in a with properties parameter, right at creation time. (A scripter normally expects that only elements, if any are needed, have to be added afterwards.) But that is not the case with making new presentations. Properties cannot be set at inception of the presentation, which needs to be created first. This does correspond with how the Add method works for a Presentation, so it should not surprise people who are accustomed to VBA.
In VBA, the only argument that can be specified with
Presentations.Add
is WithWindow, which determines whether the new presentation is visible or not. There is no way to make an invisible presentation in AppleScript, since presentation does not have a visible property to set to false. (Its main document window does, but as with many applications, the visible property of document window is read-only, and is always true.) Nor is there any command such as
hide.
At first there doesn't seem to be any properties of a presentation that you can set in AppleScript (the dictionary entry for presentation shows all properties as
r/o: read only). However, there are many properties, such as page setup, web options, slide show settings, and so on, that return objects whose own properties can be set with almost infinite choices. This is similar in every Microsoft Office
application. It means that you can set these "properties of properties" after you create the presentation but not in a make new statement. There are also new elements that can be made at the presentation, also after creation of course, and then you can modify them (that is, set the elements' own properties) as needed.
Don't forget that what VBA considers properties includes many collection objects (such as Slides), which in AppleScript are elements that you make. All other properties of the presentation class, both in VBA and in AppleScript, are read-only, except for a few such as east asian line break level and layout direction that are not available in the U.S. English version of PowerPoint.
Also, in AppleScript, there is no equivalent to the DisplayComments property, which is a read/write property. You can make comments in the Drawing Suite and set all sorts of attributes for them, but you can't control whether they are visible.
So every script that needs to make a new presentation will start off as follows:
tell application "Microsoft PowerPoint" set newPres to make new presentation tell slide 1 of newPres -- code here end tell end tell
You must set a variable of your choice to the
make
new presentation
statement, which by definition returns the object it has made, or you won't have anything to work with. You won't always be going on to
tell slide 1
to set various properties of, and make new elements at,
slide 1, but you will get around to that pretty soon in most cases.
Open an existing presentation
Opening an existing PowerPoint presentation file is simple in AppleScript. Here is the Open method in VBA:
Presentations.Open FileName:="Mac HD:Folder:Filename.ppt"
The AppleScript equivalent is the open command in the Standard Suite, as follows:
tell application "Microsoft PowerPoint" open alias "Mac HD:Folder:Filename.ppt" end tell
Note that you should properly use the alias reference form, but the PowerPoint developers have enabled a coercion, which allows you to use just the path text as an equivalent, just as in VBA. Also, in AppleScript, you can open a list of presentation files all at once if you want. Just provide the list of .ppt aliases.
You might also want to modify or get information from a presentation. In VBA, you set a variable (reference) to the result of the Open statement, which returns a Presentation object, and then set some properties of it or apply some methods to it.
Dim oPres As Presentation, oSlide As Slide Set oPres = Presentations.Open(Mac HD:Folder:Filename.ppt") With oPres Set oSlide = .Slides.Add(2, ppLayoutText) End With
The process of setting a variable to the result of a command is usually straightforward in AppleScript, too. However, just as in Microsoft Word, the command open from the Standard Suite does not return a result, so you cannot set a variable to the command.
Here is another option:
tell application "Microsoft PowerPoint"
open "Mac HD:Users:yourname:Desktop:Saved Pres.ppt"
set thePres to active presentation
set theSlide to make new slide at end of thePres¬
with properties {layout:slide layout text slide}
end tellYou open the presentation and then set your variable to active presentation, which is the presentation in the front. The open command always opens the file in the front of the application, so this always works if the presentation is not already open. If the presentation is already open, it does not come to the front, and you will be acting on the wrong presentation. So here's the full code you need:
tell application "Microsoft PowerPoint"
try
set thePres to presentation "Saved Pres.ppt"
on error
open "Mac HD:Users:yourname:Desktop:Saved Pres.ppt"
set thePres to active presentation
end try
set theSlide to make new slide at end of thePres ¬
with properties {layout:slide layout text slide}
end tell

