attaching spreadsheet to email?

S

Scott

I have a macro that creates an excel spreadsheet with 5 or
6 tabs of information. It saves the spreadsheet on my C
drive

How would I use the macro to then take that spreadsheet
and email it to people?

Thanks for any help
Scott
 
S

scott

Is there any other way to do this? I looked at this
program and it was about $500....that is a little steep
right now.

Thanks
Scott
 
M

[MVP] S. Clark

Cost benefit analysis of time vs. money. Worst pain there is.

Considering the fact that it is now an Excel Spreadsheet, you may need to
issue some type of SendObject command from Excel. This is with VBA code of
course, not with a query.

I don't know the exact syntax to use, but check the Excel VBA help file for
specific email capabilities. You might try posting a message to the Excel
newsgroup as well.
 
G

Gary Walter

Scott said:
I have a macro that creates an excel spreadsheet with 5 or
6 tabs of information. It saves the spreadsheet on my C
drive

How would I use the macro to then take that spreadsheet
and email it to people?

Hi Scott,

The following should give you a good starting point I believe.

It has several caveats:
1) uses early binding which typically is no-no,
but has worked for me in situations
where not a multiple/shared db...so can set
references to Outlook and DAO
and not worry about it.

2) assumes you have a table where you
store email addresses of people you
want to email your excel file to
(stored as Text, not Hyperlink)
and you manipulate a query "qryEMail"
based on this table to return those addresses
in a field "EMail"

Create a new module (say "modEMail")
and cut and paste following code into it.
Change "qryEMail" to the name of your query,
and "EMail" to the name of field in query that
contains email addresses in function SendMsg.


'***** start of code ******************
Public Function SendMsg()
On Error GoTo Err_SendMsg
Dim appOutlook As New Outlook.Application
Dim itm As Outlook.MailItem
Dim strExcelPath As String
Dim strToMe As String

strExcelPath = "C:\somedir\myfile.xls" 'replace w/ actual path
strToMe = (e-mail address removed) 'replace w/ your email address

'Create new mail msg
Set itm = appOutlook.CreateItem(olMailItem)

With itm
.To = strToMe
.BCC = GetEMailAddresses("qryEMail", "EMail")
.Subject = "The Excel file" 'replace w/ your subject
.Body = "Here be the Excel file." 'replace w/your Body msg
.Attachments.Add strExcelPath
'display msg before hitting Send
.Display
End With

Exit_SendMsg:
Exit Function
Err_SendMsg:
MsgBox Err.Description
Resume Exit_SendMsg

End Function

Function GetEMailAddresses(pQueryName As String, _
pFieldName As String) As String
On Error GoTo Err_GetEMailAddress
Dim rs As DAO.Recordset
Dim varTemp As Variant

varTemp = ""

Set rs = CurrentDb.OpenRecordset(pQueryName)
rs.MoveFirst
Do While Not rs.EOF
varTemp = varTemp & "<" & rs.Fields(pFieldName) & ">, "
rs.MoveNext
Loop
'remove ending comma and space
GetEMailAddresses = Left(varTemp, Len(varTemp) - 2)
'Debug.Print varTemp
rs.Close

Exit_GetEMailAddress:
Set rs = Nothing
Exit Function

Err_GetEMailAddress:
MsgBox Err.Description
Resume Exit_GetEMailAddress

End Function
..*** end of code ***************


I've never used a macro ever, so here be
how I would run this code:

Then put a command button on some form.
Give it a caption like "Send Message"
In its properties, next to line "OnClick"
type in the following:

=SendMsg()

{possibly you could put this function call
in your macro...but I have no experience here}

Please respond back if I have misunderstood
or was not clear about something.

(Outlook code was adapted from
http://www.woodyswatch.com/access/archtemplate.asp?4-07)

Good luck,

Gary Walter
 

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