Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    New York, NY
    Thanked 12 Times in 11 Posts

    Style name (Word XP)

    I have a macro that toggles the font in a style so that the hidden attribute is on or off. The style name is bcc. In some documents, the style name is Bcc (not initial cap). The lind of code .Styles("bcc").Font.Hidden = True raises an error.... because the style name does not exist. My error trap then creates the style, but at this point Word says the style cannot be created because the style already exists. What woulc be the best way of handling this? The user can run this macro from any place in the document, so I can't assume that I'm at a paragraph styled with Bcc. Can I rename a style?

    Richard Barrett

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Style name (Word XP)

    This is strange - when I run code using style names, it appears to be case insensitive. It doesn't matter whether I look for a style named "bcc" or "Bcc" or "bCC". From the online help:
    <hr>Use Styles(index), where index is the style name, a WdBuiltinStyle constant or index number, to return a single Style object. You must exactly match the spelling and spacing of the style name, but not necessarily its capitalization.<hr>
    (Italics are mine).

    If it really doesn't work, you might loop through all styles until you find the one you need:

    Dim stl As Style
    For Each stl In ActiveDocument.Styles
    ' Compare lower case
    If LCase(stl.NameLocal) = "bcc" Then
    ... ' do your stuff here
    Exit For
    End If
    Next stl

Posting Permissions

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