Styles

V

vbasean

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
 
L

Lene Fredborg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top