Excel VBA:Sub 过程与函数过程的使用指南
1. VBA Sub 过程示例:排序工作表
在 Excel VBA 中,Sub 过程是一种可以执行特定任务的代码块。下面是一个用于对活动工作簿中的所有工作表进行排序的 Sub 过程示例:
Application.EnableCancelKey = xlDisabled
' Get the number of sheets
SheetCount = ActiveWorkbook.Sheets.Count
' Redimension the array
ReDim SheetNames(1 To SheetCount)
' Store a reference to the active sheet
Set OldActiveSheet = ActiveSheet
' Fill array with sheet names
For i = 1 To SheetCount
SheetNames(i) = ActiveWorkbook.Sheets(i).Name
Next i
' Sort the array in ascending order
Call BubbleSort(SheetNames)
' Turn off screen updating
Application.ScreenUpdating = False
' Move the sheets
For i = 1 To SheetCount
ActiveWorkbook.Sheets(SheetNames(i)).Move _
Before:=Acti
订阅专栏 解锁全文
7160



被折叠的 条评论
为什么被折叠?



