Macro in word 2003 not working in word 2007

V

vestlink

Hi.

I used this macro to create a toc based on formatting in word 2003, bu
as I upgraded to 2007, the macro is no longer working. I suspect tha
the part of the macro that replaces formatting is the wrong-doer, but
don't really know.

Could anybody help me pointing out what my problem seems to be?

Best regards,

Nicolai

Sub innholdsfortegnelse()
'
' innhold Macro
'
'
Dim oHF As HeaderFooter
Dim oPara As Paragraph
' go to the beginning of doc
' make a new Section
With Selection
.HomeKey Unit:=wdStory
.InsertBreak Type:=wdSectionBreakNextPage
End With
' make the NEXT Section headers unlinked
For Each oHF In ActiveDocument.Sections(2).Headers
oHF.LinkToPrevious = False
Next
' just in case, make all footers unlinked as well
For Each oHF In ActiveDocument.Sections(2).Footers
oHF.LinkToPrevious = False
Next
' make the first page have no header content
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Text = ""
' replace all paragraphs Times Roman, 13, bold as Heading 3
For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.Font.Size = 13 And _
oPara.Range.Font.Bold = True And _
oPara.Range.Font.Name = "Times New Roman" Then
oPara.Style = "Heading 3"
End If
If oPara.Range.Font.Size = 11 And _
oPara.Range.Font.Bold = True And _
oPara.Range.Font.Name = "Times New Roman" Then
oPara.Style = "Heading 3"

End If
Next
' make Section 2 start as Page 1
With ActiveDocument.Sections(2).Headers(1).PageNumbers
.RestartNumberingAtSection = True
.StartingNumber = 1
End With
' insert ToC
Selection.HomeKey Unit:=wdStory
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, Text:="TOC ", _
PreserveFormatting:=False
End Su
 
G

Graham Mayor

I can't imagine it ever working as written. There are a few full stops
(periods) missing that would throw errors when run

e.g in the following lines (which here have the stops replaced).

With Selection
.HomeKey Unit:=wdStory
.InsertBreak Type:=wdSectionBreakNextPage
End With

and the following would have been highlighted in red for the same reason.

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
..Range.Text = ""

That aside - what is it now not doing that it did before?


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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