send attached document by email

N

Newbie

Try something like: (this is for Exchange Server)
NB You would pass a string with the path to the attachement:
AttachmentPath = "c:\filelocation\file.txt"

Sub SendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim strMessage As String
strMailTo= "(e-mail address removed)"
strMailCc = "(e-mail address removed)"
strMessage = "File attached" 'whatever you want to appear in the message
' 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(strMailTo)
objOutlookRecip.Type = olTo

If Not Nz(strMailCc, "") = "" Then
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(strMailCc)
objOutlookRecip.Type = olCC
End If
' Set the Subject, Body, and Importance of the message.
.Subject = "Your subject message goes here"
.Body = strMessage

.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
.Display

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

HTH
 
F

Focus

How can I send by email a document as an attached file
the "SendObject " command dose not support this action

thanks
 
N

Newbie

Sorry - I'm not sure if this works with Outlook Express - it assumes you
have the full Outlook package
 
G

Guest

Check Microsoft Knowledge Base Article 20998, "How to: Use
Automation to Send a Microsoft Outlook Message using
Access 2000"
 

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