Send e-mail automatically

  toga 10:34 01 Jul 04

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.

What is Google Allo? What is Google Duo? Google Allo UK release date and features: Google Allo is…

1995-2015: How technology has changed the world in 20 years

iOS 10 troubleshooting tips: Simple fixes for the most common iOS 10 problems, from network…