访问 Office 应用程序状态栏中的进度栏

发布于 2024-07-07 17:43:11 字数 66 浏览 9 评论 0原文

我为 Word 和 Excel 构建 VBA 应用程序,有什么方法可以访问有时出现在 Office 状态栏中的进度条。

I build VBA applications for both Word and Excel, is there any way to access the progress bar that sometimes appears in the Office status bar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ぇ气 2024-07-14 17:43:11

下面将模拟 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

The following will simulate a progress bar in Excel's status bar:

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
樱花坊 2024-07-14 17:43:11

另外,我建议记录 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

I would recommend in addition, to record the current state of the StatusBar, then restore it when everything is done.

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
唐婉 2024-07-14 17:43:11

我没有访问进度栏,但我过去曾使用过类似的方法将任务状态文本放置在状态栏中......

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

I have not accessed the progress bar, but I have in the past used something like this to place task status text in the status bar...

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
恍梦境° 2024-07-14 17:43:11

AFAIK,没有办法重现 Word & 所使用的蓝色点线。 Excel 显示接近 100% 的进度,例如打开文件时。

我记得曾经看到一些代码在状态栏中复制它,但它很复杂,当使用 Application.StatusBar 在状态栏中说“X%完成”就足够了时,我不会推荐它。

AFAIK, there is no way to reproduce the blue line of dots used by Word & Excel to show progress towards 100%, eg when opening a file.

I remember once seeing some code to replicate it in the status bar, but it was complex, and I wouldn't recommend it, when it is quite sufficient instead to say "X% complete" in the status bar, using Application.StatusBar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文