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.
------------------------------
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.
|