Including an attachment in email

G

Guest

I am trying to attach a file to email I am sending via the code below.
Unfortunately, assigning a file name to .Attachments does not do it. Can
anyone tell me how to make this work? Thanks.

Sub Send_Message(Recipients As String, BodyText As String)
'You must add a reference to the Microsoft outlook Library
On Error GoTo SE_Err
Dim source As Range
Dim dest As Workbook
Dim myshape As Shape
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set source = Nothing
On Error Resume Next
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "(e-mail address removed)"
'.To = Recipients
.CC = ""
.BCC = ""
.Subject = "2005 Budget Adjustments Explanation"
.Body = BodyText
'.HTMLBody = RangetoHTML
.Attachments = "C:\Documents and Settings\doug.GNJPM\My
Documents\Excel\Development\2005 Budget Certification Form.doc"
.Send 'or use .Display
End With
SE_Exit:
Set OutMail = Nothing
Set OutApp = Nothing
Set dest = Nothing
Application.ScreenUpdating = True
Exit Sub
SE_Err:
Print Error(Err.Number) ' print error message.
'Resume Next
GoTo SE_Exit
End Sub
 
G

Guest

I found the solution elsewhere in this forum. Just needed to add a ".Add" to
the ".Attachments" as:

.Attachments.Add "c:\My Documents\book.doc"
 
S

Sue Mosher [MVP-Outlook]

If you looked it up in Outlook VBA help, you'd see that Attachments is a
collection. To add a new member to the collection, you use its Add method.
The file path will be an argument for Add.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top