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
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