我正在使用 VBA 处理 excel 表:我正在尝试测试进度条。我已经完成了设计,如下图:
代码下方userForm
:
'PLACE IN YOUR USERFORM CODE
Private Sub UserForm_Initialize()
#If IsMac = False Then
'hide the title bar if you're working on a windows machine. Otherwise, just display it as you normally would
Me.Height = Me.Height - 10
HideTitleBar.HideTitleBar Me
#End If
End Sub
代码下方Module
:
'PLACE IN A STANDARD MODULE
Sub LoopThroughRows()
Dim i As Long, lastrow As Long
Dim pctdone As Single
lastrow = Range("A" & Rows.Count).End(xlUp).Row
'(Step 1) Display your Progress Bar
ufProgress.LabelProgress.Width = 0
ufProgress.Show
For i = 1 To lastrow
'(Step 2) Periodically update progress bar
pctdone = i / lastrow
With ufProgress
.LabelCaption.Caption = "Processing Row " & i & " of " & lastrow
.LabelProgress.Width = pctdone * (.FrameProgress.Width)
End With
DoEvents
'--------------------------------------
'the rest of your macro goes below here
'
'
'--------------------------------------
'(Step 3) Close the progress bar when you're done
If i = lastrow Then Unload ufProgress
Next i
End Sub
当我按下 时Debug
,它会突出显示:
ufProgress.LabelProgress.Width = 0
更多信息
UserForm 名称是 ( ufProgress ),UserForm 左上角的标签,将用于显示指示状态名称的文本 ( LabelCaption ) ...以及 UserForm 名称上的框架 ( FrameProgress ).. Finlay,另一个标签, 即将增长的进度指标名称 ( LabelProgress ) ..
任何建议...
亲切的问候