• Finding Direct Formated Styles

    • This topic has 7 replies, 4 voices, and was last updated 13 years ago.
    Author
    Topic
    #482910

    Iโ€™m trying to get a list of a all styles in a document. However, some styles are not named other than by their direct formatting notation (such as โ€œ16 pt. Italic, Shadowโ€). These styles do not show up in Find or through (the following) code. Other variations include direct modification of an existing style (โ€œList2 + Boldโ€), or part of a Normal style. They do appear in the Styles Pane but not the Import/Export Organizer.

    How can I find these programmatically?

    Code:
    Public Sub MyFindStyles()
        On Error GoTo MyErrorHandler
       
        Dim currentDocument As Document
        Set currentDocument = ActiveDocument
       
        Dim myStyle As Style
        For Each myStyle In currentDocument.Styles
            Debug.Print myStyle.NameLocal
     
            DoEvents
        Next
       
        Exit Sub
     
    MyErrorHandler:
        MsgBox “MyFindStyles” & vbCrLf & vbCrLf & “Err = ” & Err.Number & vbCrLf & “Description: ” & Err.Description
    End Sub
    
    Viewing 2 reply threads
    Author
    Replies
    • #1330291

      I don’t know how to find them programmatically, but they are not styles. Instead they are styles with direct formatting. The ones you see like “16 pt. Italic, Shadow” are formatting on Normal. As far as I’ve been able to tell, the others always show the style name first, then +, then the formatting description. If the style + formatting is used many times, you may want to make a style. In many cases they would have to be converted to character styles, though.

      HTH,
      Pam

      • #1330383

        ….turn off Keep Track of Formatting in the options. Then you will see only actual styles in the list.

        – Jessica

        • #1330680

          ….turn off Keep Track of Formatting in the options. Then you will see only actual styles in the list.

          I’ve recently discovered that in Word 2010 that even with Keep Track of Formatting turned off, you’ll still see styles like “Heading 1 + Bold” in the styles pane. To really turn this off, open the Styles Pane and click Options… at the bottom of the pane. Then uncheck any checked boxes in the “Select formatting to show as styles:” section. (Thanks to Hans V!) Make sure you click the radio button to turn it off for all documents using the template.

          Manual formatting is sometimes mandatory — you can’t eliminate its use. Occasionally, you just have to adjust a single heading’s space above in order to look right… Unfortunately, without turning off the above, this will show up as a “style” even if it only appears once. I think of it as an extension of the format painter and just one more tool that MSFT provided to undermine their very powerful styles feature — and all the more reason to turn this off.

          Best, Kim

          P.S. Just checked — this is true for Word 2007, too.

    • #1330402

      Thanks! That is good to know. But that’s the very reason I want to find them programmatically: We shouldn’t be having direct-formatted modified named styles. It sounds like there is no way to programmatically find these deviations?

      • #1330442

        You would have to go through each paragraph and compare the actual formatting of the paragraph to the base format. Here is something that sort of does it. I can’t remember where I got, and I may even have either written or tweaked it myself, though I doubt it. It compares specific aspects of the paragraph’s actual format to the formatting in the basic paragraph style. It adds comments on the non-conforming paragraphs. You could do something else to them, of course.

        Sub DetectDirectFormatting()
        Dim p As Paragraph
        Dim sCommentText As String
        Dim sStyle As String

        With ActiveDocument
        For Each p In .Paragraphs
        ‘ line below ignores those end of table row things that are strange

        If Not IsParaEndOfRow(p) Then
        sCommentText = “”
        sStyle = p.Style
        If p.Range.ParagraphFormat.Alignment .Styles(sStyle).ParagraphFormat.Alignment Then
        sCommentText = sCommentText & “Alignment. ”
        End If
        If p.Range.Bold .Styles(sStyle).Font.Bold Then
        sCommentText = sCommentText & “Bold. ”
        End If
        If p.Range.Italic .Styles(sStyle).Font.Italic Then
        sCommentText = sCommentText & “italic. ”
        End If
        If p.Range.Font.Name .Styles(sStyle).Font.Name Then
        sCommentText = sCommentText & “Font. ”
        End If
        If p.Range.ParagraphFormat.LineSpacing .Styles(sStyle).ParagraphFormat.LineSpacing Then
        sCommentText = sCommentText & “Line Spacing. ”
        End If
        If p.Range.ParagraphFormat.SpaceAfter .Styles(sStyle).ParagraphFormat.SpaceAfter Then
        sCommentText = sCommentText & “Space After. ”
        End If

        If p.Range.ParagraphFormat.LeftIndent .Styles(sStyle).ParagraphFormat.LeftIndent Then
        sCommentText = sCommentText & “Left Indent. ”
        End If
        If p.Range.ParagraphFormat.OutlineLevel .Styles(sStyle).ParagraphFormat.OutlineLevel Then
        sCommentText = sCommentText & “outline level. ”
        End If
        ‘ Additional items here
        ‘If p.Range.ListFormat.ListTemplate .Styles(sStyle).ListTemplate Then
        ‘sCommentText = sCommentText & ” listTemplate ”
        ‘End If

        If sCommentText “” Then
        .Comments.Add p.Range, sCommentText
        End If

        End If
        Next p
        End With
        End Sub

    • #1330576

      Thanks for the code! Perhaps not the ideal solution but it addresses it.

      • #1330577

        Sure. You could replace the line that creates the comment with lines that reset the paragraph and character formatting, if you’re feeling brave and don’t want to approve each change.

        Replace this:

        If sCommentText “” Then
        .Comments.Add p.Range, sCommentText
        End If

        with something like this:

        If sCommentText “” Then
        .Comments.Add p.Range, sCommentText
        else

        p.Range.ParagraphFormat.Reset
        p.Range.Font.Reset

        End If

    Viewing 2 reply threads
    Reply To: Finding Direct Formated Styles

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: