Discussion:
Styles
(too old to reply)
DMc2007
2008-10-01 15:34:01 UTC
Permalink
Hi

How can list all the text that uses style Heading 1?

Regards

D
vbasean
2008-10-01 16:15:01 UTC
Permalink
Sub listheaders()
Dim p As Paragraph
For Each p In ActiveDocument.Paragraphs
If p.OutlineLevel = wdOutlineLevel1 Then
Debug.Print p.Range
End If
Next
End Sub
Post by DMc2007
Hi
How can list all the text that uses style Heading 1?
Regards
D
Lene Fredborg
2008-10-01 16:30:02 UTC
Permalink
The macro below inserts all text with style Heading 1 in a new document.

Another approach: create a Table of Contents (TOC) containing only Heading
1. The TOC is a field but you can convert it to normal text if you select the
TOC and press Ctrl+Shift+F9.

Sub ListHeading1Paras()
Dim oPara As Paragraph
Dim oDocH1 As Document
Dim oDoc As Document

Set oDoc = ActiveDocument
Set oDocH1 = Documents.Add

'Make sure oDocH1 starts empty and with style Normal
With oDocH1
.Range = ""
.Paragraphs(1).Style = oDoc.Styles(wdStyleNormal)
End With

'Iterate through all paragraphs in active document
'If style is Heading 1, insert text in oDocH1
For Each oPara In oDoc.Paragraphs
If oPara.Style = oDoc.Styles(wdStyleHeading1) Then
oDocH1.Range.InsertAfter oPara.Range.Text
End If
Next oPara

'Clean up
Set oDoc = Nothing
Set oDocH1 = Nothing

End Sub
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
Post by DMc2007
Hi
How can list all the text that uses style Heading 1?
Regards
D
Loading...