Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    list all styles in a document (XP)

    I am pretty much a word novice. I need to output to rtf a document with a number of styles in it, with some type of arbitrary control character before and after each paragraph . This is to allow a DOS based layout program recognize where the different styles. Does anyone have anything like this?
    I.e. this should search the document, and at the beginning of each paragraph put the style name for that paragraph preceded by a @ and at the end preceded by a &.

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

    Re: list all styles in a document (XP)

    Here is a simplistic solution. I haven't tested it on complicated documents.

    Sub AddStyleIndicators()
    Dim par As Paragraph
    Dim stl As Style
    Dim rng As Range
    For Each par In ActiveDocument.Content.Paragraphs
    Set stl = par.Style
    Set rng = par.Range
    rng.InsertBefore "@" & stl.NameLocal
    Set rng = ActiveDocument.Range(rng.Start, rng.End - 1)
    rng.InsertAfter "&" & stl.NameLocal
    Next par
    Set rng = Nothing
    Set stl = Nothing
    Set par = Nothing
    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: list all styles in a document (XP)

    Thanks Hans it works perfectly, and I might even learn something from this.

  4. #4
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: list all styles in a document (XP)

    Is there a way it could also give me a list of all the styles in the document, or is there another easier way to do this?
    Thanks

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

    Re: list all styles in a document (XP)

    It depends on how fancy you want it to be. If you type InUse into the immediate window and press F1, you will see an example of all styles that are "in use" in the current document. The help item also indicates why this is not perfect: if a style has ever been used in the document, it will be listed as "in use" for ever more even if all text formatted with that style has been removed. To find out which styles are really in use is more complicated. I have attached a macro that does this; I forgot where I got it from (perhaps her, in the Lounge, or else from the Word MVP site, but I can't find it there now)
    Attached Files Attached Files

  6. #6
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: list all styles in a document (XP)

    thanks

Posting Permissions

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