Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 27th, 2007, 09:28 PM
Registered User
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Mail thru Excel Macro Abhinav Excel VBA 14 May 15th, 2011 04:02 AM
Macro to send an email with an attachment in it samputha Excel VBA 2 August 13th, 2009 09:12 PM
Excel Macro - Send Email and Attachments robmill101 Excel VBA 1 October 21st, 2008 08:10 AM
Send mail and attachments with PHP mail function Lofa Beginning PHP 1 June 2nd, 2008 03:24 PM
close a program using macro greatmanu Excel VBA 1 September 11th, 2003 01:41 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.