By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


EmailMsgBox

This is an example of extending VBA by creating a new function.

Problem:

You want to pop up a MsgBox to the user but also send an email to yourself that something went wrong.

Another way to do this would be to log the error to a file and then have an Excel/VBA process to monitor the file.



Function EmailMsgBox(sText As String) As Variant
'This routine will email the support person and display a message box
Dim sOrigText As String

sOrigText = sText

WarnDev sText



MsgBox sOrigText

If Dir("C:\stop.txt") <> "" Then
    Stop
End If



End Function