Re: Microsoft: the experts in crazy-making
Re: Microsoft: the experts in crazy-making
- Subject: Re: Microsoft: the experts in crazy-making
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 15 Mar 2007 02:58:06 -0700
- Thread-topic: Microsoft: the experts in crazy-making
On 3/14/07 10:26 PM,
"applescript-users-bounces+berkowit=email@hidden"
<applescript-users-bounces+berkowit=email@hidden> wrote:
> On Mar 14, 2007, at 8:08 PM, Larry the O wrote:
>
>> But it always starts seraching from the beginning of the document no
>> matter what I do. How do I tell this silly program to start searching
>> from somewhere other than the beginning?
>
> Here's a script which uses the selection object as the range to search.
> It searches for the string "foo" in the fifth paragraph. If found, it
> returns true, otherwise false.
>
>
> tell application "Microsoft Word"
> set myRange to create range active document start (start of content
> of ¬
> text object of paragraph 5 of active document) end (end of content ¬
> of text object of paragraph 5 of active document)
> select myRange
>
> -- now paragraph 5 is selected
>
> set selFind to find object of selection
> set content of selFind to "foo"
> set forward of selFind to true
> execute find selFind
> end tell
>
To select just paragraph 5 for searching there's a much simpler way:
set myRange to text object of paragraph 5 of active document
select myRange
(The rest of Olof's script works the same way on that range.)
But to work on the rest of the document after the title, you would need to
create range, but don't count every character, just go to the last
paragraph:
set myRange to create range active document start (start of content of ¬
text object of paragraph 5 of active document) end (end of content ¬
of text object of paragraph -1 of active document)
You could do that less wordily like this:
tell active document
set myRange to create range start (start of content of ¬
text object of paragraph 5) end (end of content ¬
of text object of paragraph -1)
end tell
One interesting thing is that the Dictionary is wrong about the result of an
'execute find' command - it does not return an 'execute find result' (which
has a text range that could be selected if you were searching just a range
rather than the selection). As Olof says the result is just true or false,
so you do have to select the range to search first if you want the result
selected as well.
The Word AppleScript Reference Olof points to does tell you about the
correct boolean result.
>
> To maintain your sanity scripting Word, I really recommend the Word
> 2004 AppleScript Reference which you can download from mactopia:
>
> http://www.microsoft.com/mac/resources/resources.aspx?
> pid=asforoffice
Definitely recommended. Maybe this will come out better as a clickable link:
<http://www.microsoft.com/mac/resources/resources.aspx?pid=asforoffice>
--
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