Something like this ?
Dim OA As Outlook.Application
Dim MI As Outlook.MailItem
Set OA = CreateObject("Outlook.Application")
Set MI = OA.CreateItem(olMailItem)
With MI
.To = "somebody@somewhere.com"
.Subject = "Some short info"
.Body = "Some detailed info"
.Attachments.Add "\path\to\file"
.Send
End With
Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
You have to reference the Microsoft Outlook Object Library:
while in VBE, menu Tools -> References ...
Or just use late binding, ie replace this:
Dim OA As Outlook.Application
Dim MI As Outlook.MailItem
by this:
Dim OA As Object
Dim MI As Object
Const olMailItem = 0
Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Thanks for the code. It works. But here's the weird thing. To reiterate, this is a VBAccess app and I added the email code to an existing module. This module queries a database and populates the results in an excel file -- which I wanted to be taken as an email attachment and then sent automatically. The weird thing is when I run the macro which calls the function in which the email code resides, the email and its attachment are sent. But when I run the program from the Macro Scheduler, which causes the app to run at a specific time daily, it completely bypasses the email code while it does the other tasks specified in the program. No errors are being spit out by Access or VB. Don't understand what might be the issue here. Do you have any insight?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.