我为 Word 和 Excel 构建 VBA 应用程序,有什么方法可以访问有时出现在 Office 状态栏中的进度条。
JonnyGold
问问题
7558 次
4 回答
4
下面将模拟 Excel 状态栏中的进度条:
Public Sub UpdateStatusBar(percent As Double, Optional Message As String = "")
Const maxBars As Long = 20
Const before As String = "["
Const after As String = "]"
Dim bar As String
Dim notBar As String
Dim numBars As Long
bar = Chr(31)
notBar = Chr(151)
numBars = percent * maxBars
Application.StatusBar = _
before & Application.Rept(bar, numBars) & Application.Rept(notBar, maxBars - numBars) & after & " " & _
Message & " (" & PercentageToString(percent) & "%)"
DoEvents
End Sub
于 2008-11-20T17:38:15.877 回答
3
另外,我建议记录 StatusBar 的当前状态,然后在一切完成后恢复它。
Dim OldStatus
With Application
OldStatus = .DisplayStatusBar
.DisplayStatusBar = True
.StatusBar = "Doing my duty, please wait..."
End With
' Do what you do best here (you can refresh the .StatusBar message with updted, as needed)
With Application
.StatusBar = False
.DisplayStatusBar = OldStatus
End With
于 2008-10-22T19:35:11.600 回答
0
我没有访问进度条,但我过去曾使用过类似的东西将任务状态文本放在状态栏中......
Sub StatusBarExample()
Application.ScreenUpdating = False
' turns off screen updating
Application.DisplayStatusBar = True
' makes sure that the statusbar is visible
Application.StatusBar = "Please wait while performing task 1..."
' add some code for task 1 that replaces the next sentence
Application.Wait Now + TimeValue("00:00:02")
Application.StatusBar = "Please wait while performing task 2..."
' add some code for task 2 that replaces the next sentence
Application.Wait Now + TimeValue("00:00:02")
Application.StatusBar = False
' gives control of the statusbar back to the programme
End Sub
于 2008-10-20T09:10:44.093 回答
0
AFAIK,没有办法重现 Word 和 Excel 使用的蓝点线来显示 100% 的进度,例如在打开文件时。
我记得曾经在状态栏中看到一些代码来复制它,但它很复杂,我不推荐它,当使用 Application.StatusBar 在状态栏中说“X% 完成”就足够了。
于 2008-10-26T11:49:44.323 回答