Need macro to send email via default mail program
Hello I NEED to send an email using the default email program. I was using the following code however I need to attach a file and I can not see how. PLEASE help! once I know how to attach a file then I can test this. If you know a better way that would be great too
Dim Email As String, Subj As String
Dim Msg As String, URL As String
' Get the email address
Email = Range("B1")
' Message subject
Subj = "Completed BIF from " & Range("E13")
' Compose the message
Msg = ""
Msg = Msg & "Dear Admin" & "," & vbCrLf & vbCrLf
Msg = Msg & "I am pleased to inform you that " & Range("E13") & " has complered their BIF, see attached." & vbCrLf & vbCrLf
Msg = Msg & "Customer # " & Range("C4") & vbCrLf & vbCrLf
Msg = "" & 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:00"))
Application.SendKeys "%s"
End Sub
|