2013-01-10 45 views
-1

可能重複:
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 

回答

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 
0

ActiveSheet是通過你的程序在同一張紙上,所以你只是一遍又一遍改變電流/ visble工作表的名稱。

使用線路是這樣的:

ws.Name = "herp" 

等等