Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Created June 10, 2019 08:58
Show Gist options
  • Save DataSolveProblems/d92fb0c08dd68d08b73aeb2b9ac4b203 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/d92fb0c08dd68d08b73aeb2b9ac4b203 to your computer and use it in GitHub Desktop.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call Send_Email
End Sub
Private Sub Send_Email()
Dim olNS As Namespace
Dim olMail As MailItem
Set olNS = GetNamespace("MAPI")
Set olMail = CreateItem(olMailItem)
With olMail
.Subject = "Excel File XYZ Saved by " & Application.UserName
.To = "[email protected]"
.Body = "Excel file was saved by " & Application.UserName & " on " & Format(Now(), "mm-dd-yyyy") & " at " & Format(Now(), "hh:mm:ss AM/PM")
.SendUsingAccount = olNS.Accounts.Item(1)
.Send
End With
Set olMail = Nothing
Set olNS = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment