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.
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