J
jari.ruusunen
Hi all,
I'm using CDO to send email from excel and have some problems with
attachments. If correct smtp-address is provided mail is sent with
attachment, but the attachment is somehow messed up. The original size
of the file is about 150kb but when I open the mail attachemnt is only
about 15kb... And then of course the attachment cannot be opened. What
might be the reason for this? The attachment is the same workbook I'm
working on and has been saved earlier. Code below.
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Application.ScreenUpdating = False
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1
Set Flds = iConf.Fields
With Flds
..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
smtp
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25
.Update
End With
With iMsg
Set .Configuration = iConf
If toAdd <> "" Then
.To = toAdd
.From = """Me"" <[email protected]>"
.subject = subject
.AddAttachment "C:\excelFile.xls"
.Send
Set iMsg = Nothing
Set iConf = Nothing
Application.ScreenUpdating = True
Application.Quit
End If
End With
Thanks,
Jape
I'm using CDO to send email from excel and have some problems with
attachments. If correct smtp-address is provided mail is sent with
attachment, but the attachment is somehow messed up. The original size
of the file is about 150kb but when I open the mail attachemnt is only
about 15kb... And then of course the attachment cannot be opened. What
might be the reason for this? The attachment is the same workbook I'm
working on and has been saved earlier. Code below.
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Application.ScreenUpdating = False
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1
Set Flds = iConf.Fields
With Flds
..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
smtp
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25
.Update
End With
With iMsg
Set .Configuration = iConf
If toAdd <> "" Then
.To = toAdd
.From = """Me"" <[email protected]>"
.subject = subject
.AddAttachment "C:\excelFile.xls"
.Send
Set iMsg = Nothing
Set iConf = Nothing
Application.ScreenUpdating = True
Application.Quit
End If
End With
Thanks,
Jape