Solved

sending of attachments with email using VBA in Microsoft Excel

Posted on 2007-03-28
2
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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