首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问Office应用程序状态栏中的进度栏

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

Stack Overflow用户
提问于 2008-10-20 08:55:12
回答 4查看 7.6K关注 0票数 5

我为Word和Excel构建了VBA应用程序,是否有办法访问Office状态栏中有时出现的进度条。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2008-11-20 17:38:16

下面将在Excel的状态栏中模拟一个进度条:

代码语言:javascript
复制
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
票数 4
EN

Stack Overflow用户

发布于 2008-10-22 19:35:12

此外,我建议记录StatusBar的当前状态,然后在完成所有操作后恢复它。

代码语言:javascript
复制
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
票数 3
EN

Stack Overflow用户

发布于 2008-10-20 09:10:44

我没有访问过进度条,但我过去曾使用类似这样的工具将任务状态文本放在状态栏中……

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/217816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档