vendredi 27 mars 2015

Send email on save in excel to variable list

A previous post (VB Code below) will send email to address(s) in the code each time the file is saved. Is there a way to use a variable, or point to a range in the spreadsheet, for the email addresses (so users don't have to or get to edit the VB and it can be somewhat dynamic)


Previous answer: Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)


Dim Outlook As Object, EMail As Object


Set Outlook = CreateObject("Outlook.Application")


Set EMail = Outlook.CreateItem(0)


With EMail .To = "EmailAddress1@Server.com; Email2@aol.com" .CC = "" .BCC = "" .Subject = "Put your subject here" .Body = "Add you E-Mail Message Here" .Attachments.Add ActiveWorkbook.FullName ' To add active Workbook as attachment .Attachments.Add "C:\Test.xlsx" ' To add other files just use path, Excel files, pictures, documents pdf's ect. .Display 'or use .Send to skip preview End With


Set EMail = Nothing


Set Outlook = Nothing


End Sub


Aucun commentaire:

Enregistrer un commentaire