الوصول إلى شريط التقدم في شريط الحالة في تطبيق Office
-
03-07-2019 - |
سؤال
وI بناء تطبيقات VBA على حد سواء وورد وإكسل، هل هناك أي طريقة للوصول إلى شريط التقدم الذي يظهر أحيانا في شريط المكتب.
المحلول
وسيحفز فيما يلي شريط تقدم في شريط الحالة اكسل:
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
نصائح أخرى
وأوصي بالإضافة إلى ذلك، لتسجيل الحالة الراهنة للشريط الحالة، ثم استعادته عندما يتم كل شيء.
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
وأنا لم الوصول إلى شريط التقدم، ولكن لدي في الماضي تستخدم شيئا من هذا القبيل لوضع نص حالة المهمة في شريط الحالة ...
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
وAFAIK، لا توجد وسيلة لإعادة إنتاج الخط الأزرق من النقاط المستخدمة من قبل Word و Excel لاظهار تقدم نحو 100٪، وعلى سبيل المثال عند فتح الملف.
وأتذكر أنني رأيت ذات مرة بعض رمز لتكرار ذلك في شريط الحالة، ولكنها كانت معقدة، وأنا لا أوصي به، عندما كانت كافية تماما بدلا من ذلك إلى القول "X٪ كاملة" في شريط الحالة، وذلك باستخدام تطبيق .StatusBar.