How do I send a spreadsheet through e-mail?

G

Guest

I have a current code running an automation of e-mails. I was wondering if
there is a way to send a excel spreadsheet through e-mail? I have the program
running and creating a excel spreadsheet with different worksheets. I tried
using the (SendObject) but that is only to send items within my database. The
excel spreadsheet that is created is placed in a folder in a shared drive. I
want to know if there is some type of command or coding to send an e-mail
through VBA telling it to send that spreadsheet, something other than
(SendObject)? Any help would be appreciated! Thanks!
 
S

Steven Britton via AccessMonster.com

This is a Module that works for me.

Here is the calling code from the button click

If DCount("[Tracking]", "qryExport_Paws") > 0 Then
DoCmd.TransferText acExportDelim, "QryExport_PawsSpecification",
"qryExport_Paws", _
"M:\arc enterprises\Steven Britton\Paws\Exports_Daily\
qryExport_Paws.txt"

Name "M:\arc enterprises\Steven Britton\Paws\Exports_Daily\
qryExport_Paws.txt" _
As "M:\arc enterprises\Steven Britton\Paws\Exports_Daily\Paws.csv"

SendMessagePaws ("M:\arc enterprises\Steven Britton\Paws\
Exports_Daily\Paws.csv")
Kill "M:\arc enterprises\Steven Britton\Paws\Exports_Daily\Paws.csv"

End If


and this is the another sub that sends the file.


Option Explicit
Sub SendMessagePaws(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "Daily Shipment File"
.Body = "Here is the file you requested." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
 
G

Guest

Steven this is still not working for me...I'm using Access 97 and it's not
reading some of the coding. It's not reading the "Dim" Statements to define
the variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top