Re: Word 2008 text range from Message 3 of AppleScript-Users Digest, Vol 7, Issue 88
Re: Word 2008 text range from Message 3 of AppleScript-Users Digest, Vol 7, Issue 88
- Subject: Re: Word 2008 text range from Message 3 of AppleScript-Users Digest, Vol 7, Issue 88
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 07 Feb 2010 18:53:05 -0800
- Thread-topic: Word 2008 text range from Message 3 of AppleScript-Users Digest, Vol 7, Issue 88
Title: Re: Word 2008 text range from Message 3 of AppleScript-Users Digest, Vol 7, Issue 88
There's no way to replace only the formatting (italic) of multiple wildcard found objects all in one go. (You have to set the text for a replacement, or else it's assumed to be "". So you could do it if you weren't using wildcards easily enough by just setting the content of the replacement (object) of the find object.
But it's not so hard with wildcards. You simply have to use an appropriate repeat loop, but set the wrap to find stop instead of find continue, so it doesn't go round and round forever. I get the character index (selection end) of the original selection to use as a marker, and exit the repeat loop when I get there. Also, you're lucky that you're first line of setting the selection to null didn't do anything, or the find object of it would have errored, or also been the equivalent of null.
Try this:
tell application "Microsoft Word"
set origEndPoint to selection end of selection -- integer
repeat
set selfind to find object of selection
tell selfind
set forward to true
set wrap to find stop
set match wildcards to true
set content to "($)*(%)"
end tell
execute find selfind -- selects just the found object
if not found of selfind then exit repeat
set italic of font object of selection to false
set currEndPoint to selection end of selection
tell selection to set {its selection start, its selection end} to {currEndPoint + 1, origEndPoint}
end repeat
end tell
--
Paul Berkowitz
From: Michael Tompsett <email@hidden>
Date: Mon, 08 Feb 2010 00:15:37 +0100
To: AppleScript-Users <email@hidden>
Subject: Re: Word 2008 text range from Message 3 of AppleScript-Users Digest, Vol 7, Issue 88
OK, made some progress with this after using the Wildcard feature. The following script allows me to select text between two markers.
The trick was in the correct phrasing of "set content" line, and also the line setting wildcards to true
CODE:
tell application "Microsoft Word"
set selection to null
set selfind to find object of selection
set forward of selfind to true
set wrap of selfind to find continue
set match wildcards to true
set content of selfind to "($)*(%)"
execute find selfind
end tell
END CODE
with this sample text: "More then three centuries after the $Flying Scotsman% was brought into service, it looks like the famous name $may be back% in service."
Result is that $Flying Scotsman% is highlighted.
Now that i can do that, it raises another question. In the Word 2008 Find dialog box, if "Highlight all found items in..." is ticked, then it will select all occurrences of the find request in the text body. So in the example text above, both sets of text $Flying Scotsman% and $may be back% would become highlighted in word, meaning that the style can be changed to italic to both in one go, rather than looping through the document and changing each one individually as I currently am doing.
I was wondering if it is possible to replicate the "Highlight all found items in..." part of the find request in applescript?
I can see nothing in the word 2008 dictionary for it under the find procedure.
On 7 Feb 2010, at 21:00, email@hidden wrote:
------------------------------
Message: 3
Date: Sun, 07 Feb 2010 01:23:04 +0100
From: Michael Tompsett <email@hidden>
Subject: Word 2008 text range between markers
To: email@hidden
Message-ID: <email@hidden">email@hidden>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Try as I may I just can't figure this one out. In my word document I
have sections of text which are delimited by a markers. I want to be
able to italicize the text between the markers. To do this, I presume
I need to set the text range, or possibly selection, as the text
between these two markers. And this has got me stumped.
I'm able to find and select the first marker, and then find and select
the second marker, but how do I then select the text between these two
markers or set the text as a text range so that further actions can be
made on it.
Example text is:
"More then three centuries after the $Flying Scotsman% was brought
into service, it looks like the famous name $may be back% in service."
I want to be able to italicize the text between the markers $ and %,
so in the example above "Flying Scotsman" and "may be back" would
turned into italics
Any help greatly appreciated.
_______________________________________________
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
_______________________________________________
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