Add attachment to CDO email

B

blackbox

Having trouble aading an attachment to CDO email

Sub Send_Margins()
Dim cdoConfig
Dim msgOne

Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"mail.mailserver.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25
.Update
'.Item(cdoSendUserName) = "UserName"
'.Item(cdoSendPassword) = "Password"
End With

Set msgOne = CreateObject("CDO.Message")
Set msgOne.Configuration = cdoConfig
msgOne.To = "(e-mail address removed)"
msgOne.CC = "(e-mail address removed)"
msgOne.From = "(e-mail address removed)"
msgOne.Subject = "hello"
msgOne.TextBody = "test test test"
msgOne.Attachments.Add "C:\Documents and Settings\j.doe\Desktop\MarginImp.
xls"
msgOne.Send
End Sub

I get "Type mismatch" error on this line
msgOne.Attachments.Add "C:\Documents and Settings\j.doe\Desktop\MarginImp.
xls"

also tried
Dim MI As Object
Set MI = Workbooks("C:\Documents and Settings\j.doe\Desktop\MarginImp.xls")

msgOne.Attachments = MI

but get "Subscript out of range" on the Set MI line

any ideas?
 

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