chrismacldn
New Member
- Joined
- Sep 11, 2015
- Messages
- 28
I have this code in VBA which currently works perfectly fine but I want to add to it and cant seem to get my head around it.
As it stands, when you press save on the workbook it automatically sends an email to the email address in the code stating the date and time the work book was updated.
Things I want to add:
Help on any of these would be greatly appreciated as I've been stuck for weeks!
Thanks Guys!
As it stands, when you press save on the workbook it automatically sends an email to the email address in the code stating the date and time the work book was updated.
Things I want to add:
- I would like the email to send to multiple email address'
- I would like to include the updated workbook as an attachment
- If possible I would like the email to also include the PC username of the person who updated the workbook.
Help on any of these would be greatly appreciated as I've been stuck for weeks!
Thanks Guys!
Rich (BB code):
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim answer As String
answer = MsgBox("Are you sure you want to update the rota?", vbYesNo, "Rota Update")
If answer = vbNo Then Cancel = True
If answer = vbYes Then
'open outlook type stuff
Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)
'add recipients
'newmsg.Recipients.Add ("Name Here")
newmsg.Recipients.Add ("EMAIL ADDRESS 1")
'add subject
newmsg.Subject = "Rota Update"
'add body
newmsg.Body = "Rota Update " & Format(Now, "dd-mmm-yy h-mm-ss")
newmsg.Display 'display
newmsg.Send 'send message
'give conformation of sent message
MsgBox "The rota has been updated, thank you.", , "Rota Update"
End If
'save the document
'Me.Worksheets.Save
End Sub
Last edited by a moderator: