请问VBA编程为什么运行到“Worksheets(j).Name = names(j - 1)”提示下标越界?
......Dim names As Variant
names = Array("工程概况", "工程运行管理", "防渗排水", "上游段", "闸室段", "下游段", "闸门和启闭机", "电气", "特殊病害", "柱状图")
For j = 1 To 3
Worksheets(j).Name = names(j - 1)
Next j
For j = 4 To 10
Set xlSheet = Worksheets.Add(after:=Worksheets(j - 1))
xlSheet.Name = names(j - 1)
Next j
...... --------------------编程问答-------------------- 看看你有多少个worksheets
--------------------编程问答-------------------- For j = 1 To 3
Worksheets(j).Name = names(j - 1)
Next j
这三句代码必须在当前工作簿至少有三个工作表的情况下才会运行正常,如果当前工作簿只有一个或两个工作表,就不存在Worksheets(3),当然会提示下表越界了 --------------------编程问答-------------------- 2楼说得很对 --------------------编程问答-------------------- intCount=worksheets.count
For j = 1 To incount
Worksheets(j).Name = names(j - 1)
Next j
For j = intcount+1 To intcount+6
Set xlSheet = Worksheets.Add(after:=Worksheets(j - 1))
xlSheet.Name = names(j - 1)
Next j
--------------------编程问答-------------------- 原来如此,谢谢啊
补充:VB , VBA