Re: Applying Character style in Word 2004
Re: Applying Character style in Word 2004
- Subject: Re: Applying Character style in Word 2004
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 01 Oct 2006 23:08:57 -0700
- Thread-topic: Applying Character style in Word 2004
> --THIS DOESN'T WORK
> --set style of font object of replacement of myFind to myStyle
Two reasons:
1) You are trying to set the style of the 'font object' property of the
'replacement' property. 'replacement' property is of type 'replacement'.
'replacement' class's 'font object' property is of type 'font', of course.
But 'font' class does not have a 'style' property, so that's obviously not
going to work. You can't set the style of a font object when font doesn't
have a 'style' property.
2) 'replacement' does have its own 'style' property, but that's supposedlty
of type 'base style': 102 enumerated built-in styles only. It's not an
element of type 'Word style'.
So, supposedly, you can't set the style of a replacement to any custom
styles, only to one of the 102 enumerated built-in styles of 'base style'.
(BTW, applying FOOT_REF style manually afterwards removes the bold and
re-applies the superscript since you set the superscript property of
FOOT_REF to true and didn't set the bold property. Why'd you do that?)
But, in fact, the dictionary is wrong (a bug, but of a benign variety). You
_can_ set it to your custom style! It works if you just set the style like
this:
set style of replacement of myFind to myStyle
So, I'm sure exactly what you're trying to do, but the following example
creates a style which specifies bold and no superscript, and applies that
style via replacement to all superscripts. Is that what you want? If not,
adapt it how you wish. (Before running the script, go to Format/Style and
DELETE your existing FOOT_REF style.)
tell application "Microsoft Word"
try
set myStyle to make new Word style at active document with
properties ¬
{name local:"FOOT_REF", style type:style type character}
set superscript of font object of myStyle to false
set bold of font object of myStyle to true
on error
set myStyle to Word style "FOOT_REF"
end try
set myFind to find object of text object of active document
clear formatting myFind
set superscript of font object of myFind to true
set content of myFind to ""
clear formatting replacement of myFind
set style of replacement of myFind to myStyle
set content of replacement of myFind to ""
execute find myFind replace replace all
end tell
--
Paul Berkowitz
> From: Larry McMunn <email@hidden>
> Date: Sun, 1 Oct 2006 22:26:28 -0400
> To: <email@hidden>
> Cc: Chris Haner <email@hidden>
> Subject: Applying Character style in Word 2004
>
> I need to apply a character style "FOOT_REF" to
> footnote references that a client is simply
> making superscript.
>
> I can find the superscripts and change the
> character style (apply Bold, remove Superscript,
> etc.) but I can't get the Character style change
> to work.
> ------------
> tell application "Word_2004"
> activate
> try
> set myStyle to make new Word style at active document with properties ¬
> {name local:"FOOT_REF", style type:style type character}
> set superscript of font object of myStyle to true
> on error
> set myStyle to a reference to Word style "FOOT_REF"
> end try
> set myFind to find object of text object of active document
> clear formatting myFind
> set superscript of font object of myFind to true
> set content of myFind to ""
> clear formatting replacement of myFind
> --THIS WORKS
> set bold of font object of replacement of myFind to true
> --THIS WORKS
> set superscript of font object of replacement of myFind to false
>
> --THIS DOESN'T WORK
> --set style of font object of replacement of myFind to myStyle
>
> set content of replacement of myFind to ""
> execute find myFind replace replace all
> end tell
> ------------
>
> What am I missing here?
> --
>
> Happy Automation! :-)
>
> Larry McMunn
> President
>
> McMunn Associates, Inc.
> Collingswood, NJ
> Seminole, FL
>
> Mobile: (856) 261-7018
> Main Office: (866) 671-6067
> FAX: (866) 636-4446
> ---------------------------------------------------------------
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Applescript-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> 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:
This email sent to email@hidden