I have a workbook which I would like to be able to email when I'm finished editing and before closing so I have made a command button to 'send email' via my gmail account. However it only works for an unopened workbook and it works fine when I send another workbook from the pc.
How can I modify the below code to be able to send the workbook I have open and am working on or even better would be a particular sheet from the workbook or the data from that sheet.
Tester1 is not the open workbook it's the saved one on C: that I used to test the mail
Code
Private Sub btnsendemail_Click()
Dim mail As New Message
Dim config As Configuration
Set config = mail.Configuration
config(cdoSendUsingMethod) = cdoSendUsingPort
config(cdoSMTPServer) = "smtp.gmail.com"
config(cdoSMTPServerPort) = 25
config(cdoSMTPAuthenticate) = cdoBasic
config(cdoSMTPUseSSL) = True
config(cdoSendUserName) = "xxxx.com"
config(cdoSendPassword) = "xxxx"
config.Fields.Update
mail.To = ""
mail.From = config(cdoSendUserName)
mail.Subject = "email subject"
mail.HTMLBody = "<b>emailbody</b>"
mail.AddAttachment "C:\Users\Desktop/tester1.xlsm"
On Error Resume Next
mail.Send
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "There was an error"
End If
MsgBox "your email has been sent", vbInformation, "sent"
End Sub
Display More