• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Microsoft: the experts in crazy-making
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Microsoft: the experts in crazy-making


  • Subject: Re: Microsoft: the experts in crazy-making
  • From: Larry the O <email@hidden>
  • Date: Thu, 15 Mar 2007 10:28:04 -0700

Thank you, Paul and Olaf (for both questions).

I understand object-oriented programming, but I'm struggling a bit with getting my head fully wrapped around the object structure in MS Word's AS implementation. I think the implementation is reasonable, but I can't find enough examples and the documentation (and I'm talking about the doc Olaf cited) is not organized in a way that makes it very clear to me, compared to other programming and scripting docs I've worked with.

In fairness, however, it's worth noting that, as I've said before, I'm just a user with no programming training who has been building myself tools for several years, so my knowledge is riddled with holes that make some logical things incomprehensible until someone (like you guys) points out the logic.

In this case, I understood the text object concept, but hadn't fully extended it to things like text objects of paragraphs. Of course, that's entirely logical, I just missed it.

So, I'm coming along well with your help and I think I can solve these problems now.

Thanks so much!

Larry the O

On Mar 15, 2007, at 2:58 AM, Paul Berkowitz wrote:

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 (applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
40meyersound.com
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden

_______________________________________________ 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
References: 
 >Re: Microsoft: the experts in crazy-making (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Re: Microsoft: the experts in crazy-making
  • Next by Date: OS9 vintage script-error reading txt file using InDesign 2.0
  • Previous by thread: Re: Microsoft: the experts in crazy-making
  • Next by thread: Re: Passing MS Word object specs (Larry the O)
  • Index(es):
    • Date
    • Thread