• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

sending of attachments with email using VBA in Microsoft Excel

Hello, I am trying to automate the sending of attachments with email using VBA in Microsoft Excel.

I have it working except for the attachment piece, does anyone know how to set it up so I can attach for example "C:\Temp\Text.txt"?  I've attached the code that works without the attachment piece below.

Sub Send_Email()

    Dim objOL As New Outlook.Application
    Dim objMail As MailItem

    Set objOL = New Outlook.Application
    Set objMail = objOL.CreateItem(olMailItem)
    With objMail
        .To = "first.last@yahoo.com"
        .CC = ""
        .Subject = "test email"
        .Body = "test line 1" & Chr(10) & Chr(10) _
                & "test line 2" & Chr(10) & Chr(10)
        .Attachments = ("c:\temp\text.txt")
    End With
    Set objMail = Nothing
    Set objOL = Nothing

End Sub

1 Solution
zorvek (Kevin Jones)ConsultantCommented:
.Attachments.Add = "c:\temp\text.txt"

hpsuserAuthor Commented:
Thanks Kevin, it was Attachments.Add(file), but that was the help I needed!

I'm awarding points, have a good one.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now