Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 95
Insert a Slide
Unfortunately, and unaccountably, there is no AppleScript equivalent of the InsertFromFile method that allows you to insert an existing file of saved slide(s) into a presentation. It's a bug, and should hopefully be made good in Office 2008 – look for an insert from file command.) In the meantime, here's a chance to try out do Visual Basic. You can still convert your macro, and when you get to a line using InsertFromFile, like this:
ActivePresentation.Slides.InsertFromFile _
"Macintosh HD:Users:Shared:Sales.ppt", 2, 3, 6
you would, for the moment, in PowerPoint 2004, use:
do Visual Basic "ActivePresentation.Slides.InsertFromFile _
\"Macintosh HD:Users:Shared:Sales.ppt\", 2, 3, 6"
Note the escape backslashes \ before the internal quotes, and the fact that you do not need to close the outer AppleScript quotes for each line of the quoted VBA. And do remember that this line will fail in Office 2008 – you will need to replace it with (hopefully) the new AppleScript command at that time.
Working with Existing Slides and Shapes
Getting a selected slide or shape
Often you might run into VBA code like this:
Dim oSh as Object
Set oSh = ActivePresentation.Slides(4).Shapes(8)
With oSh
.SomeProperty = "this"
.AnotherProperty = "that"
End With
This is just a reminder from Chapter 2 that 1) in AppleScript you don't need to (and can't) declare (Dim) anything as typed; 2) there are no collection objects in AppleScript, so instead of ActivePresentation.Slides(4).Shapes(8), you refer to shape 8 of slide 4 of active presentation; and 3) you can use a tell block exactly as VBA uses a With block:
tell application "Microsoft PowerPoint"
set theShape to shape 8 of slide 4 of active presentation
tell theShape
set some property to "this"
set another property to "that"
end tell
end tell
Furthermore, if you're setting 18 or so properties of theShape, you don't even need to set each one separately on its own line (although you can if you want to: it's sometimes easier to keep track of them that way): you can set them all in one long line using lists, like this:
tell theShape
set {some property, another property} to {"this", "that"}
end tell
You must use the tell block if you want to set a list of properties in one line: you cannot do so using the alternative of syntax.
As mentioned just above, there is no name property of slide in AppleScript. But because it is so useful in VBA as a way of keeping track of and referring to slides you will very often find in the macros you want to convert that the author has named each slide and shape of interest for later reference. Many macros will start out by presuming that you have selected a slide or a shape, and then will proceed to name it for future reference:
With ActiveWindow.Selection.SlideRange
.Name = "MyName"
End With
With ActiveWindow.Selection.ShapeRange
.Name = "MyName"
End With
The VBA author will no doubt have been careful to specify that you must select only one slide or shape for the Name property, whether using the SlideRange or ShapeRange property as above, or by .Selection.Slides(n).) Unfortunately, you're going to have to dispense with all this since, as mentioned above, there is no selection object in AppleScript at present in PowerPoint 2004. You will have to wait for Office 2008 in the hope that it has a selection property of the application (and of presentation) to be able to do a direct "translation" of .Selection. Read on for a workaround for PowerPoint 2004 and comments about 2008.
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine