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 32
myRange.Paragraphs(2).Range.Text Then
myRange.Paragraphs(2).Range.Delete
AmountMoved = myRange.MoveEnd(unit:=wdParagraph, Count:=1)
Else
'if two paragraphs aren't identical, add the one after
'that to my range, so it can be checked, and drop the first one,
'since it is no longer of interest.
AmountMoved = myRange.MoveEnd(unit:=wdParagraph, Count:=1)
myRange.MoveStart unit:=wdParagraph, Count:=1
End If
Loop
Although this is quite straightforward (VBA macro by Word MVP Bill Coan), some adjustments need to be made for AppleScript:
tell application "Microsoft Word"
--start with first paragraph and extend range down to second
set myRange to text object of paragraph 1 of active document
set rangeEnd to end of content of myRange
--in AppleScript a new range is made and returned, cannot alter
--ranges in place, so redefine myRange to the new range
set myRange to (move end of range myRange by a paragraph item count 1)
set newRangeEnd to end of content of myRange
set amountMoved to newRangeEnd - rangeEnd
set rangeEnd to newRangeEnd
--loop until there are no more paragraphs to check
repeat while amountMoved > 0
--if two paragraphs are identical, delete second one
--and add the one after that to myRange so it can be checked
if content of text object of paragraph 1 of myRange = ¬
content of text object of paragraph 2 of myRange then
delete text object of paragraph 2 of myRange
set myRange to text object of paragraph 1 of myRange
set rangeEnd to end of content of myRange
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine