Solved

sending of attachments with email using VBA in Microsoft Excel

Posted on 2007-03-28
2
159 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now