View Single Post
 
Old 08-17-2010, 01:46 AM
my_vine_figtree my_vine_figtree is offline Windows Vista Office 2007
Novice
 
Join Date: Aug 2010
Posts: 2
my_vine_figtree is on a distinguished road
Default Reverse order of headings throughout Word

I found the code below but it turns

BBBB
3
4
AAAA
1
2

into the following

AAAA
2
1
BBBB
4
3

instead of


AAAA
1
2
BBBB
3
4

Any ideas?

Sub reverseheadings()
'
' reverseheadings Macro
'
'
Dim iPara As Long
Dim iLastPara As Long
Dim doc As Document
Dim docNew As Document
Dim rng As Range

Set doc = ActiveDocument
Set docNew = Documents.Add
iLastPara = doc.Paragraphs.Count
Set paraHeader = docNew.Paragraphs.Add
paraHeader.Style = "Heading 1"
For iPara = doc.Paragraphs.Count To 1 Step -1
If doc.Paragraphs(iPara).Style = "Heading 1" Then
paraHeader.Range = doc.Paragraphs(iPara).Range.Sentences(1)
Set paraHeader = docNew.Paragraphs.Add
paraHeader.Style = "Heading 1"
iLastPara = iPara - 1
End If
If doc.Paragraphs(iPara).Style = "Normal" Then
Set rng = doc.Paragraphs(iPara).Range
rng.Select
Selection.Copy
Set rng = docNew.Range
rng.Collapse wdCollapseEnd
rng.Select
rng.Paste
iLastPara = iPara - 1
End If
Next iPara
End Sub
Reply With Quote