VBA E-MAIL FILE

B

bek

I am able to send an e-mail using VBA with a file link but how do I use this
same method to send the actual Excel file as an attachment?

Thanks for your help...
 
A

AlexM

On Error GoTo SendError

Dim rs As DAO.Recordset
Set rs = CurrentDb().OpenRecordset(INSERT YOUR CODE)

Dim objMessage As Object
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = strSubject & " " & Date
objMessage.From = rs.Fields("EmailAddress")
objMessage.To = strRecipient
objMessage.TextBody = strBody

If Len(strAttachment) >= 1 Then
objMessage.AddAttachment strAttachment
End If

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") =
rs.Fields("Username")

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
rs.Fields("Password")

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
rs.Fields("Server")
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send

Set objMessage = Nothing
rs.Close
Set rs = Nothing

Exit Function
 

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