Macro Mail Alert

Post number 5 has been selected as the best answer.

Status
Not open for further replies.

Atch

Member
Outlook version
Outlook 2019 64-bit
Email Account
IMAP
Hey, I've got a little problem with always missing important mails. Tried the Ablebits plugin but it's not quite what I'm looking for.

Is it possible to do the following with a macro:
1. Open a small alert window in the middle of the screen, preferably one that always stays in the foreground no matter where you click unless you close it.
2. Sound a system alert (specified wav file) on repeat every X seconds/minutes until Alert Window is closed

The following code successfully sounds an alarm for me, but not sure how to do the rest.
Code:
#If VBA7 Then ' 64-bit MS Office
    Private Declare PtrSafe Function sndPlaySound32bit Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As LongPtr) As LongPtr
#Else ' 32-bit MS Office
    Private Declare Function sndPlaySound32bit Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As LongPtr) As LongPtr
#End If


Public Sub PlaySound()
    sndPlaySound32bit "C:\Windows\Media\Alarm01.wav", &H1
End Sub
 
The new Item desktop alert action in rules does the window - but its not modal or always on top.

A simple msgbox would be modal and lock you out of Outlook until you responded. Other apps, but not Outlook, could take focus from a msgbox but Outlook is basically locked until you respond.

1687521021717.png

1687521014105.png
 
So playing a system sound or beep on a loop until msgbox or UserForm is closed is not possible? Tried playing around with SetTimer but didn't get anything to work here.
 
The player would need to loop - according this link, its SND_LOOP, SND_ASYNC

I only found C++ samples - I think it would be like this in vba. It plays until you run the macro again to stop it (could do this using a counter)
sndPlaySound32bit "C:\Windows\Media\Alarm01.wav", &H1, SND_LOOP, SND_ASYNC

 
Why did I even bother with SetTimer... Your solution seems much easier. I kinda got it to work with this:

Code:
Option Explicit

#If VBA7 Then 'make it 64bit office compatible
    Public Declare PtrSafe Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
#Else
    Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
#End If

'  flag values for uFlags parameter
Const SND_SYNC = &H0            '  play synchronously (default)
Const SND_ASYNC = &H1           '  play asynchronously

Const SND_NODEFAULT = &H2       '  silence not default, if sound not found

Const SND_MEMORY = &H4          '  lpszSoundName points to a memory file
Const SND_ALIAS = &H10000       '  name is a WIN.INI [sounds] entry
Const SND_FILENAME = &H20000    '  name is a file name
Const SND_RESOURCE = &H40004    '  name is a resource name or atom
Const SND_ALIAS_ID = &H110000   '  name is a WIN.INI [sounds] entry identifier

Const SND_ALIAS_START = 0       '  must be > 4096 to keep strings in same section of resource file

Const SND_LOOP = &H8            '  loop the sound until next sndPlaySound
Const SND_NOSTOP = &H10         '  don't stop any currently playing sound
Const SND_VALID = &H1F          '  valid flags          / ;Internal /

Const SND_NOWAIT = &H2000       '  don't wait if the driver is busy

Const SND_VALIDFLAGS = &H17201F '  Set of valid flag bits.  Anything outside
                                '  this range will raise an error
Const SND_RESERVED = &HFF000000 '  In particular these flags are reserved

Const SND_TYPE_MASK = &H170007


Sub play(Item As Outlook.MailItem)
    sndPlaySound32 "C:\Windows\Media\Alarm01.wav", SND_ASYNC + SND_LOOP
    UserForm1.Show
End Sub

Private Sub halt()
    sndPlaySound32 vbNullString, SND_ASYNC
End Sub

Sub ShowUserForm()
    UserForm1.Show
End Sub

Code:
Private Sub ToggleButton1_Click()
    sndPlaySound32 vbNullString, SND_ASYNC
    Unload Me
End Sub

Private Sub UserForm_Click()
    
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    sndPlaySound32 vbNullString, SND_ASYNC
End Sub

Though I Indeed get locked out until I close the UserForm, but that's not really an issue. I hope a certain someone will finally stop missing important mails now. 😆
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Outlook 365 Amending code so macro runs within current new mail window Outlook VBA and Custom Forms 0
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
E Copying data from e-mail attachement to EXCEL file via macro Outlook VBA and Custom Forms 38
Y VBA Macro to highlight some Keyword in mail body? Outlook VBA and Custom Forms 3
H Macro to Copy Specific content from Mail Body and Paste to Excel Outlook VBA and Custom Forms 4
P Delete mail macro Outlook VBA and Custom Forms 6
Phillip Show mail items in folder macro Outlook VBA and Custom Forms 2
Douglas Littlefield Macro to move E-mail Outlook VBA and Custom Forms 10
reza Macro to automatic reply using orignal mail Outlook VBA and Custom Forms 10
Douglas Littlefield Macro to move mail from inbox to Managed Folder Exchange Server Administration 1
L Outlook 2007 Macro Reply to E-mail Using Outlook 16
L Macro Move E-mail attachments to a PC Folder Using Outlook 16
S Outlook Macro for checking the mail is sent to outside organization Using Outlook 3
Z Trigger macro to run after a new mail is received in Outlook? Using Outlook 3
D Macro to export mail data based on assigned category Using Outlook 3
J Macro to move mail from Inbox if older than 4 days Using Outlook 4
S Outlook 2007 Macro for replying to an e-mail. Outlook VBA and Custom Forms 1
M Outlook Macro to get Exchange Info from Mail Outlook VBA and Custom Forms 25
B Macro to Change sort and collapse groups in Mail folder Outlook VBA and Custom Forms 9
H using macro for sending multiple mail in outlook Outlook VBA and Custom Forms 1
S Macro to delete e-mail containing specific texts in the subject Outlook VBA and Custom Forms 3
S how to disable security message in save attachments macro "A programis trying to access e-mail addre Outlook VBA and Custom Forms 5
N Macro in this Project are disabled Outlook VBA and Custom Forms 2
M Outlook 365 macro - automatically attach file based on subject line Outlook VBA and Custom Forms 0
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 3
H Macro to Delete Duplicate items in Outlook calendar where title is the same and date is the same Outlook VBA and Custom Forms 0
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
mrrobski68 Issue with Find messages in a conversation macro Outlook VBA and Custom Forms 1
G Creating Macro to scrape emails from calendar invite body Outlook VBA and Custom Forms 6
M Use Macro to change account settings Outlook VBA and Custom Forms 0
J Macro to Reply to Emails w/ Template Outlook VBA and Custom Forms 3
C Outlook - Macro to block senders domain - Macro Fix Outlook VBA and Custom Forms 1
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 0
S macro error 4605 Outlook VBA and Custom Forms 0
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 6
D Outlook 2016 Creating an outlook Macro to select and approve Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
M Outlook 2019 Macro not working Outlook VBA and Custom Forms 0
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
D Auto Remove [EXTERNAL] from subject - Issue with Macro Using Outlook 21
V Macro to count flagged messages? Using Outlook 2

Similar threads

Back
Top