Outlook VBA Macro: Best Way To Specify Please Wait

What is the best practice for telling the user that Macro works in Outlook? A macro can take about 1-30 seconds.

I want to avoid the appearance of the modal "msgbox" before running the macro, as this can be annoying.

I would rather avoid the hourglass hand if possible, and wondered if there is a better way.

Is there a way to post a modeless status message up while the macro is running?

(The macro that I run against the currently selected mailItem is triggered by a button on the quick access toolbar).

+3
source share
3 answers

( ) , .

Outlook :


Microsoft Outlook. , Microsoft Office.

Outlook.com .

+3

, , , .

1. , marque, 2. gif ( ..). .. 3. win api, staus bar.

, , , , "" async .

+2

@76mel, . - : EG Status

, :

  • ( F4, ShowModal false)
    • , , .
  • StartupPosition 0-Manual Top 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, reset , Excel

'Written By RobDog888 - VB/Office Guru™
'Add a Command Button so you can toggle the userform 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

,

0

Source: https://habr.com/ru/post/1731637/


All Articles