locked
Selection.Style not return what I expected RRS feed

  • Question

  • Hi

    Don't quit know how to explain my problem but here goes :-)

    We have some old documents with manually changed styles. I have a macro that will open all Word files in a folder/subfolder and then change some settings.
    I am trying to create a macro that will check the used styles and change the selection to other styleset's depending on what the original styleset was.
    My problem is that when I run "Msgbox Selection.Style" on some of the text from the old documents it just returns the style "Normal". If I check styles in Word it tells me that the style is "Arial, 10.5, bold" but it returns "Normal"

    Can anyone help me?


    /Lasse
    Thursday, October 7, 2010 12:36 PM

Answers

  • To clarify, Selection.Style returns the name of the style applied to the selection (may be undefined if the selection includes more than one paragraph).
     
    Stefan Blom
    Microsoft Word MVP


    "LasseF" wrote in message news:d28c02ac-d30a-43eb-88cb-3cdb6eb29b7b@communitybridge.codeplex.com...

    Hi

    Don't quit know how to explain my problem but here goes :-)

    We have some old documents with manually changed styles. I have a macro that will open all Word files in a folder/subfolder and then change some settings.
    I am trying to create a macro that will check the used styles and change the selection to other styleset's depending on what the original styleset was.
    My problem is that when I run "Msgbox Selection.Style" on some of the text from the old documents it just returns the style "Normal". If I check styles in Word it tells me that the style is "Arial, 10.5, bold" but it returns "Normal"

    Can anyone help me?


    /Lasse

    Stefan Blom, Microsoft Word MVP
    • Marked as answer by Sally Tang Friday, October 8, 2010 1:19 AM
    Thursday, October 7, 2010 7:29 PM

All replies

  • As far as I know, there is no way to find out which style set has been applied to a document. (Style sets are never “in” the document; when you apply a style set, it simply reformats a collection of styles in the target document.)
     
    Also, by default, the Styles pane in Word shows entries with direct formatting, but these technically aren’t styles.
     
     
    "LasseF" wrote in message news:d28c02ac-d30a-43eb-88cb-3cdb6eb29b7b@communitybridge.codeplex.com...

    Hi

    Don't quit know how to explain my problem but here goes :-)

    We have some old documents with manually changed styles. I have a macro that will open all Word files in a folder/subfolder and then change some settings.
    I am trying to create a macro that will check the used styles and change the selection to other styleset's depending on what the original styleset was.
    My problem is that when I run "Msgbox Selection.Style" on some of the text from the old documents it just returns the style "Normal". If I check styles in Word it tells me that the style is "Arial, 10.5, bold" but it returns "Normal"

    Can anyone help me?


    /Lasse

    Stefan Blom, Microsoft Word MVP
    Thursday, October 7, 2010 7:04 PM
  • To clarify, Selection.Style returns the name of the style applied to the selection (may be undefined if the selection includes more than one paragraph).
     
    Stefan Blom
    Microsoft Word MVP


    "LasseF" wrote in message news:d28c02ac-d30a-43eb-88cb-3cdb6eb29b7b@communitybridge.codeplex.com...

    Hi

    Don't quit know how to explain my problem but here goes :-)

    We have some old documents with manually changed styles. I have a macro that will open all Word files in a folder/subfolder and then change some settings.
    I am trying to create a macro that will check the used styles and change the selection to other styleset's depending on what the original styleset was.
    My problem is that when I run "Msgbox Selection.Style" on some of the text from the old documents it just returns the style "Normal". If I check styles in Word it tells me that the style is "Arial, 10.5, bold" but it returns "Normal"

    Can anyone help me?


    /Lasse

    Stefan Blom, Microsoft Word MVP
    • Marked as answer by Sally Tang Friday, October 8, 2010 1:19 AM
    Thursday, October 7, 2010 7:29 PM