迭代通过工作簿和重命名选项卡

时间:2013-01-10 23:21:39

标签: excel vba

  

可能重复:
  Excel VBA: Batch renaming sheets

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

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

ActiveSheet与您的程序相同,因此您只需反复更改当前/可见工作表的名称。

使用这样的行:

ws.Name = "herp"

等...