Results 1 to 2 of 2
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    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)?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •