Attach Excel file using Access Code and E-mail

foxhound

Board Regular
Joined
Mar 21, 2003
Messages
182
Does anyone know how to change this code to attach the Excel file "Supervisor Report.xls" located in C:\Temp\ and e-mail to joesupervisor?

DoCmd.SendObject acReport, "Supervisor Snapshot", "RichTextFormat (*.rtf)", "joesupervisor@anyweb.com", , , "Vacation, Sick, and Attendance Report", "This is a test to attach e-mail file", , ""
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
this is an access code and as such will only send Access objects (like reports, tables etc)

You need to create outlook as an object in Access and then it's straight foward. You MUST reference the Outlook 9.0 (10.0 if XP) Object Library in VBE - Tools - References.

Code:
Sub a()

Dim aOutlook As Outlook.Application, aEmail As Outlook.MailItem

Set aOutlook = GetObject(, "Outlook.Application")

If aOutlook Is Nothing Then Set aOutlook = New Outlook.Application

Set aEmail = aOutlook.CreateItem(olmailitem)

aEmail.Importance = olImportanceHigh

aEmail.Subject = "Workbook For Your Perusal - Dated " & Format(Today, "dd/mm/yy")
aEmail.Body = _
    "Attached is the Night Sheet Workbook" & vbLf & _
    "This Workbook is Password Protected." & vbLf & vbLf & _
    "Thanks," & vbLf & _
    "Brian"
    
aEmail.Attachments.Add "C:\Luke Work\Test9.xls"
    
'Code below will prevent additional email addresses on basis of code no
'ie code1 will add CSM then proceed to email posting

aEmail.Recipients.Add "j.bloggs@blogsville.com"
aEmail.Send


End Sub
 
Upvote 0

Forum statistics

Threads
1,221,532
Messages
6,160,381
Members
451,643
Latest member
nachohoyu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top