Unable to attach file using CDO mail

bblevins

New Member
Joined
Nov 3, 2008
Messages
22
I have been using CDO to send emails for quite some time. I now have a need to attach a Powerpoint file and am unable to do so.

I get a Runtime error '438': Object doesn't support this property or method when it reaches .AddAttachment.

I have verified that the file I am passing ("C:\MetricsMgr\Reports\Weekly Deck\Weekly Files\Weekly Performance 20221010.pptx") is closed. I have tried passing it in as a variable and also hard coding the path. Neither works. I have also tried attaching a text file (again, closed) both ways with no luck. Any ideas? I am running Office 2013 if that makes a difference.


VBA Code:
Sub MailSMTP(mTo As String, mCC As String, mSubject As String, mAttachment As String)
    Dim iMsg As Object
    Dim iConf As Object
    Dim mBody As String
    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.MyServer.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With

    mBody = "The RSS Weekly Performance Material is ready to view." & vbNewLine & vbNewLine & _
            "Thank you," & vbNewLine & _
            "My Name" & vbNewLine & _
            "My Number"
 
    With iMsg
        Set .Configuration = iConf
        .To = mTo
        .CC = mCC
        .BCC = ""
        .From = "<MyEmail@mailserver.com>"
        .Subject = mSubject
        .AddAttachment = mAttachment
        .TextBody = mBody
        .Send
    End With

    Set iMsg = Nothing
    Set iConf = Nothing
    Set Flds = Nothing

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi, try removing the = sign, i.e.

.AddAttachment mAttachment

AddAttachment is a method, not a property.
 
Upvote 0
Solution
FormR, a sincere thanks for making me feel like a moron for missing that. But an even bigger thanks for providing the solution. I am up and running now. Thank you...
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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