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 101
On Error Resume Next
' does it have a text frame?
If .HasTextFrame Then
' does the text frame have any text?
' see if there's any there
' before trying to alter it
If .TextFrame.HasText Then
.TextFrame.TextRange.Text = "And here we are, safely"
End If
End If
End With
End Sub
becomes:
tell application "Microsoft PowerPoint"
--get the selected shape via the handler
set selectedShape to my GetSelectedShape() -- paste it in below!
try -- to avoid error messages if shape has no text frame or no text
tell selectedShape
if has text frame then -- does it have one?
--if so, does the text frame have any text?
if has text of its text frame then -- needs 'its'
set content of text range of its text frame to ¬
"And here we are safely."
end if
end if
end tell
end try
end tell
For production work, you would put all the lines, after getting selectedShape, into an IsSafeToTouch(selectedShape) handler, sending it the selectedShape and returning a boolean true, or false under other conditions or on error, before setting the text in the main script. There would be many different places and contexts where you would call this handler before setting different text:
tell application "Microsoft PowerPoint"
--get the selected shape via the handler
set selectedShape to my GetSelectedShape() -- paste it in below!
set check to my IsSafeToTouch(selectedShape)
if check then
set content of text range of selectedShape's text frame to ¬
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine