Solved

sending of attachments with email using VBA in Microsoft Excel

Posted on 2007-03-28
2
162 Views
Last Modified: 2010-04-30
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")
        .Display
    End With
   
    Set objMail = Nothing
    Set objOL = Nothing

End Sub

Thanks
0
Comment
Question by:hpsuser
2 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 18812915
.Attachments.Add = "c:\temp\text.txt"

Kevin
0
 

Author Comment

by:hpsuser
ID: 18812951
Thanks Kevin, it was Attachments.Add(file), but that was the help I needed!

I'm awarding points, have a good one.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question