Results 1 to 5 of 5
  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

    Macro-created style reflects direct par. format (Word 2002 SP-2)

    I had been under the impression that if a style-creating macro (1) set the .BaseStyle for the new style, and (2) tweaked, say, 3 individual settings for the new style, the result would be that the new style would be identical to the BaseStyle except for the 3 tweaked settings.

    But if, at the time the style-creating macro is run, the Selection happens to be in a paragraph with one or more direct-formatted tweaks (e.g. .KeepWithNext is True, or the paragraph's font is red), then the new style created by the macro will also reflect these direct-formatted settings (unless they happen to be expressly reset by the macro's style tweaks).

    I guess my first question is why, why, why, why, why?

    My 2nd question is what to do. I can obviously create a SetStyleDefaults macro that gets called (as Step One) by every macro that creates a new style, and that individually resets every setting for which the new style might otherwise take on the Selection's direct formatting. (It appears to me that you can't use the .Reset method with either the .Font or the .ParagraphFormat of a style.) Is there an easier solution?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Macro-created style reflects direct par. format (Word 2002 SP-2)

    This is actually a very handy feature: if you apply some direct formatting, then create a new style, Word assumes that you want to include the direct formatting in the style. This is often more convenient than specifying the formatting in the New Style dialog.

    Why do you want to create a style in code? I don't remember ever having had a use for that.

  3. #3
    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

    Re: Macro-created style reflects direct par. format (Word 2002 SP-2)

    I tend to do most things with code, style-making included.

    I have a MakeNewNormal macro that turns the Word default Normal.dot into my Normal.dot (the idea being that I'll need to use it periodically after Normal.dot becomes bloated or corrupt). Among the things it does is call procedures that create the custom styles I want included in Normal.dot.

    Most of the custom styles that I'm not putting into Normal.dot are set up to be created on-the-fly when a macro tries to apply them and finds out (through error 5941 or 5834 being triggered, depending on the situation) that the style doesn't exist (yet) in that document.

    I thought that it was especially considered "recommended practice" to use VBA to create styles involving List Templates. The macros I've created for that purpose are handy not only because they create those styles in the recommended digging-to-China fashion, but also because they're set up to alternatively re-create the styles if the styles already exist in the applicable document but have somehow managed to go sideways and are in need of repair.

    I can understand Word's "handy feature" in the context of a user creating the new style through the default dialogs (although, even there, why not provide a "Reset" button?), but I would think that the VBA Styles.Add method would start you off with a clean style; or would at least include an argument you could set to get that result; or, failing that, that Word would give us an equivalent for styles of the .ClearFormatting method.

    Dear Santa...

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Macro-created style reflects direct par. format (Word 2002 SP-2)

    Hopefully some of the Word gurus have useful ideas...

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro-created style reflects direct par. forma

    > I guess my first question is why, why, why, why, why?

    My guess is that this feature evolved from the early macro language - mirroring interactive behavior in code - and was not "re-thought" for from-scratch document assembly.

    I don't see anything such as stylename.Duplicate that you could use to create a new style as an exact copy. Seems you'll have to do "something" with your insertion point. (For example, you could destroy all direct formatting in the paragraph and then Undo that change, or move to some appropriately formatted paragraph and then move back...)

Posting Permissions

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