|
本帖最后由 wan12327 于 2017-11-9 08:53 编辑
这段时间学习了好多,自己整理了一个插入目录的VBA代码,分享一下
Sub 第二页插入目录()
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="2"
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.TypeText Text:="目录"
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Application.Move Left:=-12, Top:=0
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Size = 16
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True, UseOutlineLevels:= _
True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
End Sub
|
|