Printing Style Area pane RRS feed

  • Question

  • Hi,

    I need to print the document with style information (Style Area pane) of each paragraph in the document. Is there any way to achieve this using VBA.


    Wednesday, February 5, 2014 6:28 AM


  • There's no way to print what you see, no.

    The following code can write style name | paragraph content to a table in a new document. It hasn't been extensively tested so might fail in a "complex" document. But it would at least give you a starting point...

    Sub StylePerParaOutput()
        Dim docSource As word.Document
        Dim docOutput As word.Document
        Dim para As word.Paragraph, tbl As word.Table
        Dim rowCounter As Long, nrParas As Long
        Set docSource = ActiveDocument
        Set docOutput = Documents.Add
        Set tbl = docOutput.Tables.Add(Range:=docOutput.content, _
         NumRows:=2, NumColumns:=2)
        tbl.Rows(1).Cells(1).Range.Text = "Style name"
        tbl.Rows(1).Cells(2).Range.Text = "Paragraph content"
        nrParas = docSource.Paragraphs.Count
        For rowCounter = 1 To nrParas
            Set para = docSource.Paragraphs(rowCounter)
            tbl.Rows(rowCounter + 1).Cells(1).Range.Text = _
            tbl.Rows(rowCounter + 1).Cells(2).Range.FormattedText = _
            If rowCounter <> nrParas Then
            End If
    End Sub

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, February 5, 2014 9:40 AM