PDA

View Full Version : Excel Send E-Mail on Save



stevembe
03-25-2019, 02:14 AM
Firstly thank you for taking the time to read. I have a shared Excel file and I need it to automatically e-mail me when users save the file. I have found the follow but it does not do anything when I save the file. Can anybody see the error? Many thanks in advance.


Private Sub Workbook_AfterSave(ByVal Success As Boolean)
'Updated by Extendoffice 20181102
Dim xOutApp As Object
Dim xMailItem As Object
Dim xName As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xMailItem = xOutApp.CreateItem(0)
xName = ActiveWorkbook.FullName
With xMailItem
.To = "myemailaddress.com"
.CC = ""
.Subject = "The workbook has been saved"
.Body = "Hi," & Chr(13) & Chr(13) & "File is now updated."
.Attachments.Add xName
.Display
'.send
End With
Set xMailItem = Nothing
Set xOutApp = Nothing
End Sub

Kenneth Hobs
03-25-2019, 08:00 AM
Did you comment out .Display and uncomment .Send?

Of course it won't Send unless Outlook is open or sends when it opens. Outlook can be forced open to send then...

stevembe
03-26-2019, 12:22 AM
Did you comment out .Display and uncomment .Send?

Of course it won't Send unless Outlook is open or sends when it opens. Outlook can be forced open to send then...

Many thanks Kenneth, issue is no resolved.