文件名称:VBA实现进度条的显示
文件大小:34KB
文件格式:XLSM
更新时间:2013-07-17 01:22:52
VBA,进度条
VBA实现进度条的显示 Sub Test() ' The UserForm1_Activate sub calls Main UserForm1.LabelProgress.Width = 0 UserForm1.Show End Sub Private Sub UserForm_activate() Call Main End Sub Sub Main() ' Inserts random numbers on the active worksheet Dim Counter As Integer Dim RowMax As Integer, ColMax As Integer Dim r As Integer, c As Integer Dim Completed As Single If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub Cells.Clear Application.ScreenUpdating = False Counter = 1 RowMax = 100 ColMax = 25 For r = 1 To RowMax For c = 1 To ColMax Cells(r, c) = Int(Rnd * 1000) Counter = Counter + 1 Next c Completed = Counter / (RowMax * ColMax) With UserForm1 .FrameProgress.Caption = Format(Completed, "0%") .LabelProgress.Width = Completed * (.FrameProgress.Width) End With ' The DoEvents statement is responsible for the form updating DoEvents Next r Unload UserForm1 End Sub