-1

可能重复:
Excel VBA:批量重命名工作表

谢谢您的帮助。我可能没有适当地迭代。也许我应该为活动工作表分配一个整数?

Sub TabNames()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ActiveSheet.Name = "herp"
Next ws
ActiveSheet.Name = "derp"
Next ws
ActiveSheet.Name = "herp derp"
Next ws
ActiveSheet.Name = "derp herp"
Next ws
ActiveSheet.Name = "herp herp"
Next ws
ActiveSheet.Name = "derp derp"

End Sub
4

2 回答 2

1
Sub TabNames()

Dim arrNames, x as integer

arrNames = Array("herp", "herp derp", "derp herp", "herp herp", "derp derp")

For x = 1 to ActiveWorkbook.Worksheets.Count
    ActiveWorkbook.Worksheets(x).Name = arrNames(x-1)
Next x

End Sub
于 2013-01-11T00:51:43.870 回答
0

ActiveSheet在您的过程中是同一张表,因此您只是一遍又一遍地更改当前/可见工作表的名称。

使用这样的行:

ws.Name = "herp"

ETC...

于 2013-01-10T23:33:21.777 回答