Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Using VBA to email w/ attachments

Question posted by: apa278 (Newbie) on January 21st, 2006 06:15 AM
Hello!

I'm trying to send out Outlook emails using VBA in Excel. I have a list of email recipients and variablized file names and locations listed out in Excel. I've used the SendMail function before to email out a workbook that's currently open and active, but it looks like that function won't allow any other attachments. What function can I use that will let me attach 2 files to one email?

I even went straight to the bookstore after work on a Friday night (tonight) because I'm dying to figure this out. But alas, I couldn't find anything helpful.

I would even be content for somebody to tell me that this isn't even possible... But why the heck wouldn't it be?

Thanks for reading my post,
Frances
mredge600's Avatar
mredge600
Newbie
1 Posts
September 21st, 2006
03:41 PM
#2

Re: Using VBA to email w/ attachments
Quote:
Hello!

I'm trying to send out Outlook emails using VBA in Excel. I have a list of email recipients and variablized file names and locations listed out in Excel. I've used the SendMail function before to email out a workbook that's currently open and active, but it looks like that function won't allow any other attachments. What function can I use that will let me attach 2 files to one email?

I even went straight to the bookstore after work on a Friday night (tonight) because I'm dying to figure this out. But alas, I couldn't find anything helpful.

I would even be content for somebody to tell me that this isn't even possible... But why the heck wouldn't it be?

Thanks for reading my post,
Frances


Frances, I am looking for the same thing, let me know if you have found out how to do this.
Thanks Doug
dpawloske@jsmcnamara.com

Reply
vnaz235's Avatar
vnaz235
Newbie
2 Posts
September 21st, 2006
09:47 PM
#3

Re: Using VBA to email w/ attachments
Perhaps, you can find some ideas using the following link:

http://www.rondebruin.nl/sendmail.htm

Reply
apa278's Avatar
apa278
Newbie
2 Posts
September 21st, 2006
10:57 PM
#4

Re: Using VBA to email w/ attachments
Quote:
Frances, I am looking for the same thing, let me know if you have found out how to do this.
Thanks Doug
dpawloske@jsmcnamara.com


Hi Doug,

Here's the Outlook code that I used. You could just keep adding additional Attachments.Add lines for every attachment you'd like to put in the email.

The "^k" (equiv to Ctrl+k) is the keyboard shortcut to run the "Check Names" function, which identifies the recipients listed as being in the Global Address List. "Chr(13)" represents hitting Enter. RecipList, Subject1, Msg, Path2, ExpFile, and TsrFile are all variables I defined earlier in the macro.

Set olApp = New Outlook.Application
Set olNewMail = olApp.CreateItem(olMailItem)
With olNewMail
.Display
.Recipients.Add RecipList
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys ("{TAB}")
SendKeys ("^k")
.Subject = Subject1
.Body = Msg & Chr(13) & Chr(13)
.Attachments.Add Path2 + ExpFile
.Attachments.Add Path2 + TsrFile
.Send
End With
Set olNewMail = Nothing
Set olApp = Nothing

Hope this helps!

Frances

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,871 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Visual Basic Forum Contributors