Re: UI scripting: Problematic removal of unwanted Word footnote returns
Re: UI scripting: Problematic removal of unwanted Word footnote returns
- Subject: Re: UI scripting: Problematic removal of unwanted Word footnote returns
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 11 Nov 2011 13:25:47 -0800
- Thread-topic: UI scripting: Problematic removal of unwanted Word footnote returns
On 11/11/11 6:56 AM, "Axel Luttgens" <email@hidden> wrote:
> There's also the AppleScript way, for example:
>
> tell application "Microsoft Word"
> tell document 1
> repeat with fNote from 1 to (count of footnotes)
> tell text object of footnote fNote
> if content ends with return then
> set content to text 1 thru -2 of (get content)
> end if
> end tell
> end repeat
> end tell
> end tell
>
> I'm really not fluent with Word's scripting model, so the above is certainly
> sub-optimal... but it works here on a short document in Word 2008.
Well, with 1900 footnotes to check, you could reduce the time a bit by using
a variable to send fewer Apple Events to (get content) twice or more per
loop.
tell application "Microsoft Word"
tell document 1
repeat with fNote from 1 to (count footnotes)
tell text object of footnote fNote
set fContent to content
if fContent ends with return then
set content to text 1 thru -2 of fContent
end if
end tell
end repeat
end tell
end tell
There's a way of using Word's 'find' object and 'execute find' command to
replace double-returns (return & return) with a single return, which would
catch even the final footnote in the document the way Word always ends with
a CR, but I doubt that it's appreciably faster since it still has to loop
through every footnote - plus it would also catch any double returns within
footnotes, unlikely but possible.
There is a very cool concept in Word called a 'story range', and you can get
the content of the 'footnotes story' story range that gets the text of all
the document's footnotes in a single contiguous text range. I was hoping
that doing a find-replace ('execute find with replace') to replace double
returns with single return using 'replace all' could do this in one fell
swoop. Unfortunately, it doesn't seem to do anything in the actual document.
I'll keep playing with that and see if I can find a method for it that does
work - it would be a big time saver.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden