Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
vestlink vestlink is offline
external usenet poster
 
Posts: 1
Default Macro in word 2003 not working in word 2007


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(wdHeaderFooterP rimary) _
.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




--
vestlink
  #2   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Macro in word 2003 not working in word 2007

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(wdHeaderFooterP rimary) _
..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(wdHeaderFooterP rimary) _
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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mouse is not working in Word 2007 antoine Microsoft Word Help 6 June 20th 08 03:38 PM
Spellcheck not working in Word 2007 cynthiavee Microsoft Word Help 0 September 3rd 07 11:42 PM
Working on a file with both 2003 and 2007 bdalton Microsoft Word Help 2 June 1st 07 05:33 PM
Word 2007 Dictionary not working UrbanGrafix Microsoft Word Help 1 March 10th 07 01:47 AM
Upgrade to 2007 from 2003, Spell Checker object not working Shusheng Li Microsoft Word Help 1 July 29th 06 03:04 PM


All times are GMT +1. The time now is 05:43 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"