I have some code that sets up some emails from Access to Outlook, but I want to add an attachment to each email. I have this code below and it works, the only problem is the new line that I have put in: .Attachments = "P:\...
It causes a run time error and I can't work out why, any ideas?
Sub MattSendMessage(Name As String, OutlookName As String, MessageTitle As Variant, Message As Variant)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the recipient to the email.
Set objOutlookRecip = .Recipients.Add(OutlookName)
objOutlookRecip.Type = olTo
' Set the subject, body and importance of the email.
.Subject = MessageTitle
.Body = Message
.Importance = olImportanceNormal
.Attachments = "P:\Corporate Audit Database\Recs Downloads Database\2008\G July 08\Sent to business\Amanda Taylor.html"
' Resolve the email address name.
objOutlookRecip.Resolve
' Only display the mail message, not send.
.Display
End With
End Sub
It causes a run time error and I can't work out why, any ideas?
Sub MattSendMessage(Name As String, OutlookName As String, MessageTitle As Variant, Message As Variant)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the recipient to the email.
Set objOutlookRecip = .Recipients.Add(OutlookName)
objOutlookRecip.Type = olTo
' Set the subject, body and importance of the email.
.Subject = MessageTitle
.Body = Message
.Importance = olImportanceNormal
.Attachments = "P:\Corporate Audit Database\Recs Downloads Database\2008\G July 08\Sent to business\Amanda Taylor.html"
' Resolve the email address name.
objOutlookRecip.Resolve
' Only display the mail message, not send.
.Display
End With
End Sub