G
Guest
I get a Run-time error '13'" Type mismatch, when I try to run a VBA macro
to use an email template to create an email, and send an attachment
When I click the debug button, the following line is highlighted:
Set objOutlookAttach = .Attachments.Add(strAttch01Nam)
Any insights or suggestions would be much appreciated.
Thanks,
Marceepoo
P.s. Here's the whole macro:
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("(e-mail address removed)")
' 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
to use an email template to create an email, and send an attachment
When I click the debug button, the following line is highlighted:
Set objOutlookAttach = .Attachments.Add(strAttch01Nam)
Any insights or suggestions would be much appreciated.
Thanks,
Marceepoo
P.s. Here's the whole macro:
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("(e-mail address removed)")
' 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