Run-time error '13'" Type mismatch & .Attachments.Add

M

Marceepoo

I'm having trouble with a VBA procedure designed to [1] use an email
template to create an email, and [2] send an attachment with the email.
When I try to run it, I get a Run-time error '13'" Type mismatch.
When I click the debug button, the following line is highlighted:
Set objOutlookAttach = .Attachments.Add(strAttch01Nam)

Does anyone have any ideas why I'm getting that error, and how to address
the problem?

Thanks,
Marceepoo

Here's my code:

Sub CreateFromTemplate()
Dim myOlApp As Outlook.Application
Dim myItem As Outlook.MailItem
Dim strTemplatNam As String
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.MailItem
Dim strAttch01Nam As String
'
strTemplatNam = "C:\Documents and Settings\marxp\Application
Data\Microsoft\Templates\bcc_NM.oft"
strAttch01Nam = "E:\Archive.2005-04-21-00-30.rar.lst.txt"
'
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItemFromTemplate(strTemplatNam)
'
With myItem
' Add the To recipient(s) to the message. Substitute
' your names here.
'Set objOutlookRecip = .Recipients.Add("[email protected]")
' objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(strAttch01Nam) Then
Set objOutlookAttach = .Attachments.Add(strAttch01Nam)
End If
End With
'
myItem.Display
End Sub
 
Top