Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Applescript select text range between 2 markers

767 views
Skip to first unread message

mik...@officeformac.com

unread,
Feb 6, 2010, 7:17:04 PM2/6/10
to
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel 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.

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 it would be "Flying Scotsman" and "may be back".

Any help greatly appreciated.

John McGhie

unread,
Feb 6, 2010, 9:25:46 PM2/6/10
to
I can't do this in AppleScript, but it's very similar to the way you do it
in VBA.

You can use either the range or the selection object, then use the Extend
method:

Selection.Extend Character:="%"

That will extend the selection right until the first % sign. You need to
somehow protect against a "runaway" condition if there is any possibility
that the % sign may not be there.

However, you can do this with the Replace tool without needing script:

In Find/Replace, set $*% as your Find string.

Specify "Use wildcards" so the * matches "any number of characters" so you
are not searching for $<any characters>%

In the Replace box, specify Format>Font>Italic. Make sure the Replace box
contains no characters, and ... voila!

Hope this helps

On 7/02/10 8:17 AM, in article 59bb2...@webcrossing.JaKIaxP2ac0,
"mik...@officeformac.com" <mik...@officeformac.com> wrote:

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

--

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:jo...@mcghie.name


mik...@officeformac.com

unread,
Feb 7, 2010, 8:49:09 AM2/7/10
to
That was definitely of some help, and i can find the items between markers using the wildcard. What I now want to know if it is possible to mimick the "Highlight all items found" feature in the applescript.

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

I can now use this applescript to find and select the first occurrence - i would like to be able to highlight ALL occurrences though:

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

I'm looking in the dictionary for any clues as to the "Highlight All Found" but no luck. Anyone else know?

John McGhie

unread,
Feb 8, 2010, 11:55:49 PM2/8/10
to
Use the Replace object to replace the text formatting. There are multiple
options on the Format tab, including bold, italic, highlighting, colours.
No marching red ants any more (thank god...) but almost everything else is
available.

Then Execute your Find with Replace All set to True :-)

Cheers


On 7/02/10 9:49 PM, in article 59bb2...@webcrossing.JaKIaxP2ac0,
"mik...@officeformac.com" <mik...@officeformac.com> wrote:

This email is my business email -- Please do not email me about forum

0 new messages