双击这个模块,写入下面的代码:
Sub UpdateTOC()
Dim oSh As Object
Dim oToc As Worksheet
Dim vRemarks As Variant
Dim lCt As Long
Dim lRow As Long
Dim lCalc As Long
Dim bUpdate As Boolean
'分别提取工作表即时状态中的屏幕更新及是否为自动计算的状态并重新设置
bUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
lCalc = Application.Calculation
Application.Calculation = xlCalculationManual
'检查工作表ToC是否存在,如果不存在,请插入一个
If Not IsIn(Worksheets, "ToC") Then
With Worksheets.Add(Worksheets(1))
.Name = "ToC"
End With
Set oToc = Worksheets("ToC")
'设置工作表网格线、行标题和列标题的显示效果
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayHeadings = False
Else
(待续)
我20多年的VBA实践经验,全部浓缩在下面的各个教程中: