Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old September 27th, 2007, 10:28 PM
Registered User
Join Date: Sep 2007
Location: , , .
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

Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 11:32 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.