Send e-mail automatically

  toga 10:34 01 Jul 2004
Locked

I am trying to send an e-mail and attachment automatically (at the click of a button) using the following VBA. The e-mail is send OK but without the attachment (via outlook over a network). When I try to include the attachment (additional code indicated by ??) I get an error message, any ideas.

Sub callMessage()
??Dim attach As Varient

??'Set attachment path
??attach = "Workbook.Worksheets("Sheet1").Activate"

'argument = False so e-mail is not displayed before sending
SendMessage(False, ??attach)

End sub

Sub SendMessage(DisplayMsg As Boolean, Optional AttachementPath)
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)

'Add the recipient to the message
Set objOutlookRecip = objOutlookMsg.Recipient.Add("Kevin Nelson")
objOutlookRecip.Type = olTo

'Set the subject and body
objOutlookMsg.Subject = "This is an automated message"
objOutlookMsg.Body = "Body of message"

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

End sub

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

WPA2 Hack Latest News: How Secure is your Wi-Fi?

Photoshop CC 2018 released with new Curvature Pen and better brush tools

Best kids apps for iPhone & iPad

Comment utiliser Twitter ?