Graham
Fri Mar 14 04:11:28 PDT 2008
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
My web site www.gmayor.com
Word MVP web site
http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
vestlink wrote:
> Hi.
>
> I used this macro to create a toc based on formatting in word 2003,
> but as I upgraded to 2007, the macro is no longer working. I suspect
> that the part of the macro that replaces formatting is the
> wrong-doer, but I 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 Sub