Results 1 to 2 of 2
2005-03-26, 20:09 #1
- Join Date
- May 2003
- Los Angeles, California, USA
- Thanked 2 Times in 2 Posts
Style-setting syntax (Word 2002 SP-2)
To set an object's Style property, Word accepts either a string (the style's name) or a style object (among other options). Using the name is simpler (e.g. rngX.Style = "Body Text"), but most of the sample code I see (including here in the Lounge) seems to use the longer object syntax -- e.g., rngX.Style = rngX.Document.Styles("Body Text").
Are there reasons to avoid the simpler syntax (either generally or in certain scenarios)?
2005-03-26, 20:48 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: Style-setting syntax (Word 2002 SP-2)
If you're setting a built-in style, you can use the symbolic constant for the style: rngX.Style = wdStyleBodyText. This option is to be preferred for built-in styles because it is independent of the local language. "Body Text" would fail on my Dutch language system, but wdStyleBodyText works OK.
I'm not aware of reasons to avoid the shorter syntax for custom styles, but perhaps one of the experts will comment on that.