向用户指示宏正在 Outlook 中运行的最佳做法是什么?宏可能需要大约 1-30 秒才能完成。
我想避免在宏运行之前弹出模式“msgbox”,因为这可能很烦人。
如果可能,我宁愿避免使用沙漏光标,并想知道是否有更好的方法。
有没有办法在宏运行时放置非模态“状态”消息?
(我针对当前选定的 mailItem 运行的宏 - 它通过快速访问工具栏上的按钮启动)。
这篇关于最佳实践的文章(也是这篇文章)说使用状态栏。
更改状态栏
无法更改 Microsoft Outlook 中的状态栏文本。状态栏不会像在其他 Microsoft Office 对象模型中那样公开。
Outlook.com 为进度框提供代码。
有几件事会让人想起,我相信其他人也会有想法。
1.显示一个带有进度条的表单,报告进度,如果您无法报告进度,则进度条处于标记模式 2.显示一个带有图片框的表单,里面有您最喜欢的动画 gif(旋转披萨等) . 您可以关闭按钮等。 3.使用win api来玩outlook状态栏
不知道你在你的宏中做什么,你可能不得不处理保持表单“置顶”并将异步进度注入其中。
干杯
马库斯
扩展@76mel 的答案,一个很好的方法是使用非模态用户表单。只需像这样的标签和标题就可以使事情变得非常简单:
我喜欢做的是将用户表单设置为:
ShowModal
为 false)
StartupPosition
to0-Manual
和Top
and设置为Left
100 之类的值,以便状态表单出现在屏幕的左上角(不妨碍默认情况下出现在中心的任何其他消息)将标签设置value
为用户表单首次加载时的默认文本
Public strStatus As String
Public Const defaultStatus As String = "Default status text" 'set this to whatever you want
Sub statusReporter()
frmStatus.Show
'''
'Your code here
'''
frmStatus.lblStatus = "Step 1"
'...
frmStatus.lblStatus = "Step 2"
'...
'''
'Unload the form
'''
frmStatus.lblStatus = defaultStatus
frmStatus.Hide
End Sub
请注意,与 Excel 一样,Application.Statusbar
如果您打算稍后在同一个 Excel 实例中使用它,则必须将用户表单重置为其默认值 也可以选择使用它
'Written By RobDog888 - VB/Office Guru™
'Add a Command Button so you can toggle the userform's topmost effect
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private mlHwnd As Long
Private Sub UserForm_Initialize()
Dim overTim As Single
overTim = Timer
mlHwnd = FindWindow("ThunderDFrame", "Status") 'Change "Status" to match your userforms caption
Do While mlHwnd = 0 And Timer - overTim < 5
mlHwnd = FindWindow("ThunderDFrame", "Status")
DoEvents
Loop
'Set topmost
SetWindowPos mlHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
在用户表单代码本身中始终保持在最前面