2008-10-20 42 views

回答

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 
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 
2

我会建议此外,记录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 
0

据我所知,是没有办法复制打开文件时使用的Word Excel的&显示进展100%,例如点的蓝线。

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

相关问题