Run-time error '13'" Type mismatch when I run my VBA procedure

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
 
D

Dmitry Streblechenko

MailItem.Attachments.Add returns an instance of the Outlook.Attachment
object, not Outlook.MailItem.
You need to dim objOutlookAttach appropriately.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Guest

Dear Dmitry,
First, thank you. Could I impose on you to show me:
1. How to dim objOutlookAttach appropriately?
2. Where I could find some info that explains what I did, and what I should
have done?

Thanks for taking the time. It's very much appreciated.

marceepoo
 
D

Dmitry Streblechenko

1. Dim objOutlookAttach As Outlook.Attachment
2. You need to look at what the method returns and dim the variable you use
to store the result accordingly.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top