|
试试以下的代码,将你的工作簿插入一个新工作表:SheetNames. 然后运行此代码.
原理小妖同学已经给出, 工作表名写入列后,把此列数据排序,然后再用FOR移动工作表顺序.
Sub SortSheets()
Dim I As Integer, ii As Integer
Dim ShtName As String
On Error Resume Next
If ActiveWorkbook.Sheets.Count > 1 Then
Application.ScreenUpdating = False
With ThisWorkbook.Sheets("SheetNames")
.Columns(1).Clear
For I = 1 To ActiveWorkbook.Sheets.Count
.Cells(I, 1) = Sheets(I).Name
Next
.Columns(1).Sort Key1:=.Cells(1, 1), Order1:=xlAscending
For ii = I - 1 To 1 Step -1
ShtName = .Cells(ii, 1)
ActiveWorkbook.Sheets(ShtName).Move Before:=ActiveWorkbook.Sheets(1)
Next
End With
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
MsgBox "Worksheet sorting completed.", vbInformation
Application.ScreenUpdating = True
End If
End Sub |
|