工作中常常使用Excel + Vba进行一些数据的操作,在读取成千上万行数据时就非常需要一个进度显示。虽然vba自带有Active控件的进度条,但使用后发现效果并不理想。
于是自制了一个,在状态栏显示,效果如图:
代码:
'自定义的进度条,在状态栏显示
Function GetProgress(curValue, maxValue)
Dim i As Single, j As Integer, s As String
i = maxValue / 20
j = curValue / i
For m = 1 To j
s = s & "■"
Next m
For n = 1 To 20 - j
s = s & "□"
Next n
GetProgress = s & FormatNumber(curValue / maxValue * 100, 2) & "%"
End Function
调用方式示例:
rs.Open sql, connXls, 1
Dim p As Integer: p = 0
Do While Not rs.EOF
p = p + 1
'在状态栏显示
Application.StatusBar = GetProgress(p, rs.RecordCount)
……
非常地实用吧,呵呵。