CreateStyleFromShape doesn't work?

Trying to create a new style from a shape:

ActiveDocument.StyleSheet.CreateStyleFromShape ActiveSelectionRange.FirstShape, "character"

But this code causes error 'Cannot create empty styles'.

Also, why CreateStyleFromShape returns Styles but not a Style?

  • Sancho said:

    Trying to create a new style from a shape:

    ActiveDocument.StyleSheet.CreateStyleFromShape ActiveSelectionRange.FirstShape, "character"

    But this code causes error 'Cannot create empty styles'.

    • If I select a text shape that does not already have a style applied to it, then run your code, it creates a "top level" Character Style.

    • If I select a text shape that has a style applied to it, then manually change something on that shape that overrides the style (e.g., change the text fill color), and then run your code, it  creates a new Character Style that is a "child" of the other style.

    • If I select a text shape that already has a style applied to it, and no manual changes have been made to that shape that would override some characteristic defined by the style, then running that code produces the "cannot create empty styles" message.

    When I use this to create a style from a shape - in the cases where there is no error - then the newly-created style is applied to that shape.