View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
blackbox blackbox is offline
external usenet poster
 
Posts: 1
Default Add attachment to CDO email

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 = "
msgOne.CC = "
msgOne.From = "
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?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1