jadie
06-05-2006, 05:23 AM
I have a macro that, based on the users selection on a userform will insert up to 30 different files into my document.
I then insert a cover sheet, page down and insert a TOC. This works exactly how I want it to when I put a breakpoint in after the insertion of the files (before the cover sheet and TOC) but when I let it run by itself, it puts the TOC at the top (above the cover sheet).
Has me baffled. Here's the code:
'
' go to top and insert cover sheet
'
Selection.HomeKey Unit:=wdStory
Call InsertFile("Cover Sheet.doc")
Selection.InsertBreak Type:=wdPageBreak
'
' insert table of contents
'
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveUp Unit:=wdScreen, Count:=1
Selection.TypeText Text:="TABLE OF CONTENTS"
Selection.MoveLeft Unit:=wdCharacter, Count:=17, Extend:=wdExtend
Selection.Font.Name = "Garamond"
Selection.Font.Size = 14
Selection.Font.Bold = True
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.TypeParagraph
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=1, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
I then insert a cover sheet, page down and insert a TOC. This works exactly how I want it to when I put a breakpoint in after the insertion of the files (before the cover sheet and TOC) but when I let it run by itself, it puts the TOC at the top (above the cover sheet).
Has me baffled. Here's the code:
'
' go to top and insert cover sheet
'
Selection.HomeKey Unit:=wdStory
Call InsertFile("Cover Sheet.doc")
Selection.InsertBreak Type:=wdPageBreak
'
' insert table of contents
'
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveUp Unit:=wdScreen, Count:=1
Selection.TypeText Text:="TABLE OF CONTENTS"
Selection.MoveLeft Unit:=wdCharacter, Count:=17, Extend:=wdExtend
Selection.Font.Name = "Garamond"
Selection.Font.Size = 14
Selection.Font.Bold = True
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.TypeParagraph
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=1, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With