怪,明明早上通过的呀!录制宏也是“标题1”,可现在不行了,改为以下代码即可:
我已将其中的“标题”与前十二段相同。
Sub Contents()
Dim i As Paragraph, n As Byte, a As Byte, b As Byte, x As Long, DelRange As Range
Application.ScreenUpdating = False
a = 2
b = 13
x = 0
For Each i In ActiveDocument.Paragraphs
x = x + 1
For n = a To b
If x > b Then
If i.Range = ActiveDocument.Paragraphs(n).Range Then
i.Range.Select
Selection.Style = ActiveDocument.Styles(wdStyleHeading1)
a = a + 1
End If
End If
Next
Next
Set DelRange = Range(ActiveDocument.Paragraphs(2).Range.Start, ActiveDocument.Paragraphs(13).Range.End)
DelRange.Delete
ActiveDocument.Paragraphs(2).Range.Select
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
Application.ScreenUpdating = True
End Sub
aCVis3gK.zip
(48.4 KB, 下载次数: 93)
|