

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 29
my ReplaceInRange(findText, replaceText, theRange)
end if
end repeat
end repeat
end repeat
end tell
end ReplaceEverywhere
on ReplaceInRange(findText, replaceText, theRange)
tell application "Microsoft Word"
set findObject to find object of theRange
tell findObject
set format to false
set content to findText
set content of its replacement to replaceText
set wrap to find stop
end tell
execute find findObject replace replace all
end tell
end ReplaceInRange
Two things to note here: you'll see that in the ReplaceInRange handler that does the work for each range, we have used a tell block to the findObject (the find object property of the text range) as explained in Chapter 3.
But whereas in VBA the Execute Method could also be placed inside the "With" block, just like all the Properties, the equivalent thing does not at first seem to work with the execute find command in AppleScript even though it takes the same direct parameter (findObject) as well as the properties. It works fine when placed outside the tell block and findObject specifically referenced as the direct parameter. Commands whose direct parameter is the target of a tell block should act on the targeted object without problem, but AppleScript seems to be a little confused. In fact, you can place execute find inside the tell block if you include the term 'it' to make it clear what the direct object is:
tell findObject
set format to false
set content to findText
set content of its replacement to replaceText
set wrap to find stop
execute find it replace replace all
< Previous Page Next Page>

- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine