我必须在工作簿中重命名大约200个Excel工作表,并且还需要对它们进行排序。 任何人都知道这个宏。 提前谢谢。
答案 0 :(得分:1)
用它来排序
Sub SortWorkBook()
Dim xResult As VbMsgBoxResult
xResult = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) & "Clicking No will sort in Descending Order", vbYesNoCancel + vbQuestion + vbDefaultButton1, xTitleId)
For i = 1 To Application.Sheets.Count
For j = 1 To Application.Sheets.Count - 1
If xResult = vbYes Then
If UCase$(Application.Sheets(j).Name) > UCase$(Application.Sheets(j + 1).Name) Then
Sheets(j).Move after:=Sheets(j + 1)
End If
ElseIf xResult = vbNo Then
If UCase$(Application.Sheets(j).Name) < UCase$(Application.Sheets(j + 1).Name) Then
Application.Sheets(j).Move after:=Application.Sheets(j + 1)
End If
End If
Next
Next
End Sub
用于重命名
Sub RenamingSheets()
nmbr = InputBox("enter first number(enter only number) ", "Renaming Sheets")
For ws = 1 To Worksheets.Count
Sheets(ws).Name = "SheetName" & nmbr
nmbr = nmbr + 1
Next ws
End Sub