VBA Type Mismatch 13 - WHat am I missing?

E_DPSG

Board Regular
Joined
Jul 17, 2008
Messages
82
Ok - So, I posted about an error I was receiving related to the Outlook call a while back. I went around that completely and am just going to use SMTP to send an email directly (very similar to vbs, with obvious modifications for excel execution).

I am getting a type mismatch error when assigning the attachment with the following syntax:

Code:
        Dim AttachmentFile As String 
....
Set objCDOMsg = CreateObject("cdo.message")
    Set objCDOCfg = CreateObject("cdo.configuration")
    Set objFields = objCDOCfg.Fields
    objFields.Item("[url=http://schemas.microsoft.com/cdo/configuration/sendusing]Error[/url]") = 2
    objFields.Item("[url=http://schemas.microsoft.com/cdo/configuration/smtpserver]Error[/url]") = "MyMail.Server.com"
    objFields.Update
    Set objCDOMsg.Configuration = objCDOCfg
....
        AttachmentFile = Sheets("Email_Distribution").Range("H" & i).Value
        objCDOMsg.Attachments.Add (AttachmentFile)

When setting the attachment, I get a Run-TIme Error: '13' Type Mismatch.

When I use the alternate:

objCDOMsg.AddAttachment = AttachmentFile

I do not receive this error, yet I need to attach multiple documents during the call.

Did I miss something here that is so obvious that I am blind to the issue?

Thanks!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Ok - So, I posted about an error I was receiving related to the Outlook call a while back. I went around that completely and am just going to use SMTP to send an email directly (very similar to vbs, with obvious modifications for excel execution).

I am getting a type mismatch error when assigning the attachment with the following syntax:

Code:
        Dim AttachmentFile As String 
....
Set objCDOMsg = CreateObject("cdo.message")
    Set objCDOCfg = CreateObject("cdo.configuration")
    Set objFields = objCDOCfg.Fields
    objFields.Item("[URL="http://schemas.microsoft.com/cdo/configuration/sendusing"]Error[/URL]") = 2
    objFields.Item("[URL="http://schemas.microsoft.com/cdo/configuration/smtpserver"]Error[/URL]") = "MyMail.Server.com"
    objFields.Update
    Set objCDOMsg.Configuration = objCDOCfg
....
        AttachmentFile = Sheets("Email_Distribution").Range("H" & i).Value
        objCDOMsg.Attachments.Add (AttachmentFile)

When setting the attachment, I get a Run-TIme Error: '13' Type Mismatch.

When I use the alternate:

objCDOMsg.AddAttachment = AttachmentFile

I do not receive this error, yet I need to attach multiple documents during the call.

Did I miss something here that is so obvious that I am blind to the issue?

Thanks!

It looks like you are trying to add an object usin only its name. If the attachment is an xl file then it would be:
Code:
objCDOMsg.Attachments.Add Workbooks(AttachmentFile)
to add the file object.
 
Upvote 0
Thanks!!! Something so obvious. Will give it a go tomorrow morning when Citrix is back up. Cheers!
 
Upvote 0

Forum statistics

Threads
1,222,827
Messages
6,168,482
Members
452,192
Latest member
FengXue

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top