• 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: Styles in MS Word
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Styles in MS Word


  • Subject: Re: Styles in MS Word
  • From: Paul Berkowitz <email@hidden>
  • Date: Sun, 23 Jan 2005 00:26:18 -0800

Title: Re: Styles in MS Word
On 1/22/05 3:59 PM, "Hanaan Rosenthal" <email@hidden> wrote:

> What I meant was styles, not CSS.
> How for instance do you create a new style and apply properties to it?

OK. A few things to keep in mind:

1. The class in question is 'Word style', which you'll find in the Text Suite.

2. 'Word style' is not an element of the application but of document. This is the same in the UI, where every document has its own set of styles, although every document comes with the full set of built-in styles already in place (I think there are 163 of those). Usually just modifying a built-in style will do the trick, but you can make your own if you wish.

3. The 'style' property of many, many objects - such as paragraph, paragraph format, text range etc - is a long list of enumerations (style normal/style envelope address/style envelope return/style body text/... etc.) - about 102 of the most used built-in styles (as appears in the Formatting Palette, more or less). These are useful for _setting_ built-in styles, good for any localization. (This was added at my request, actually.) That's because when you _get_ a style property, it's actually returned as "Normal", "Heading 1", etc. - the 'name local' of the style, as Unicode text, not as a Word style object. That can be convenient but is not really proper AppleScript (it came from the OLE model). It wouldn't be good if you could only set styles with localized names. They'll be fixing that so the enumerations always work, getting and setting. At the moment

    style of paragraph 1 of active document = style normal

returns false when the style is Normal, since the style is returned as "Normal", not 'style normal'. But you can set the style of a paragraph to text range to 'style normal' and that will be Normal. Clear? ;-) You'll also find the names of your own custom styles available after you make them.

4. 'paragraph format' is a weird class. It's not an element of anything - not application nor document nor anything else. So you can't 'make new custom paragraph format with properties {} at'  anywhere and then use it as a property of the custom style you create. It's really just a record, like those fake classes of some osaxen. So you need to first make your Word style, then you can set the properties of its paragraph format to whatever you want.

5. The font object property of Word style (and of lots of other classes like 'text range') is [r/o] only in the sense that you can't "change" the font object of an object to some other font object. But you can set just about all its own properties (see 'font' class) to whatever you want. So again, you have to make the Word style first, then set the properties of its font object.

6. There's an error where the dictionary refers to the color property of various classes as of type 'RGB color'. It's not: AppleScript's 'RGB color' is a list of three integers 0-65535. Word's color property is a list of three integers 0-255. MS needs to either conform to RGB color or create their own 'Microsoft color' class. (There's a good reason why it's 256-based in VBA.) To transfer a color from RGB color to MS color, take the square root of each 65536-based integer, And the square for vice-versa transfer from Word to regular RGB color. But it doesn't work in Excel.

Here's an example:


tell application "Microsoft Word"
    set customStyle to make new Word style at active document with properties {base style:style body text, name local:"Custom Style"}
    tell paragraph format of customStyle
       set alignment to align paragraph justify
       set hyphenation to false
       set keep with next to true
       set space before to 10.0
        set space after to 8.0
        set widow control to true
       set word wrap to true
   end tell
   tell font object of customStyle
       set name to "Comic Sans MS" -- sets the font
        set color to {123, 234, 56}
        set bold to true
       set kerning to 8.0
        set font size to 14
    end tell
   set style of paragraph 3 of active document to customStyle
   get style of paragraph 3 of active document
   
--> "Custom Style"
end tell


If you want to use Custom Style in other documents, make it in a template instead of in a document, and use the template to make the other documents.

--
Paul Berkowitz
 _______________________________________________
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

References: 
 >Re: Styles in MS Word (From: Hanaan Rosenthal <email@hidden>)

  • Prev by Date: Folder Action Script question
  • Next by Date: Re: Do shell script question - non sudoer user
  • Previous by thread: Re: Styles in MS Word
  • Next by thread: title of window 1 as text
  • Index(es):
    • Date
    • Thread