Dear All,
I am using the coding below to create a message to send out daily, What I need to do is attach the current workbook to the email message. Here is the coding I have so far, I can figure out how to attach the file to the message I am creating.
Sub auto_close()
Dim Msgs, response, style
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Msgs = "Do you want to send the file to Exeter"
style = vbYesNo + vbInformation
response = MsgBox(Msgs, style)
If response = vbYes Then
Application.ScreenUpdating = False
' Get the email address
Email = "anyone@help.com"
' Message subject
Subj = "Daily Derby Stats"
' Compose the message
Msg = ""
Msg = Msg & "Dear All" & "." & vbCrLf & vbCrLf
Msg = Msg & "Please find attached the daily report"
Msg = Msg & " for yesterday." & vbCrLf & vbCrLf
Msg = Msg & "If you have any queries can you please let me know." & vbCrLf & vbCrLf
' Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20"
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20"
' Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A"
' Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
' Execute the URL (start the email client)
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
' Wait two seconds before sending keystrokes
Application.Wait (Now + TimeValue("0:00:01")
Application.SendKeys "%s"
ActiveWorkbook.Save
Else
ActiveWorkbook.Save
End If
End Sub
any help greatly appreciated.
Rob.
I am using the coding below to create a message to send out daily, What I need to do is attach the current workbook to the email message. Here is the coding I have so far, I can figure out how to attach the file to the message I am creating.
Sub auto_close()
Dim Msgs, response, style
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Msgs = "Do you want to send the file to Exeter"
style = vbYesNo + vbInformation
response = MsgBox(Msgs, style)
If response = vbYes Then
Application.ScreenUpdating = False
' Get the email address
Email = "anyone@help.com"
' Message subject
Subj = "Daily Derby Stats"
' Compose the message
Msg = ""
Msg = Msg & "Dear All" & "." & vbCrLf & vbCrLf
Msg = Msg & "Please find attached the daily report"
Msg = Msg & " for yesterday." & vbCrLf & vbCrLf
Msg = Msg & "If you have any queries can you please let me know." & vbCrLf & vbCrLf
' Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20"
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20"
' Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A"
' Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
' Execute the URL (start the email client)
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
' Wait two seconds before sending keystrokes
Application.Wait (Now + TimeValue("0:00:01")
Application.SendKeys "%s"
ActiveWorkbook.Save
Else
ActiveWorkbook.Save
End If
End Sub
any help greatly appreciated.
Rob.