Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problem in mail attachment when using CDO

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"" "
.subject = subject
.AddAttachment "C:\excelFile.xls"
.Send

Set iMsg = Nothing
Set iConf = Nothing
Application.ScreenUpdating = True
Application.Quit
End If
End With

Thanks,
Jape

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Problem in mail attachment when using CDO

According to Ron de Bruin's site for all things Excel/Email:
http://www.rondebruin.nl/cdo.htm
<Quote
Don't remove the TextBody line in the code. If you do you can't open the
attachment (bug in CDO).
If you don't want to have text in the body use this then .TextBody = ""
</Quote
I see you do not have .TextBody .

Does that help ?

NickHK

wrote in message
oups.com...
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"" "
.subject = subject
.AddAttachment "C:\excelFile.xls"
.Send

Set iMsg = Nothing
Set iConf = Nothing
Application.ScreenUpdating = True
Application.Quit
End If
End With

Thanks,
Jape



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Problem in mail attachment when using CDO

Also, according to Ron, you can't send the active workbook. .SaveCopyAs
first and send that in the attachment.

NickHK

wrote in message
oups.com...
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"" "
.subject = subject
.AddAttachment "C:\excelFile.xls"
.Send

Set iMsg = Nothing
Set iConf = Nothing
Application.ScreenUpdating = True
Application.Quit
End If
End With

Thanks,
Jape



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problem in mail attachment when using CDO

Yep, that did the trick. All the thanks in the world to you! This
helped me a lot...

Jape

According to Ron de Bruin's site for all things Excel/Email:
http://www.rondebruin.nl/cdo.htm
<Quote
Don't remove the TextBody line in the code. If you do you can't open the
attachment (bug in CDO).
If you don't want to have text in the body use this then .TextBody = ""
</Quote
I see you do not have .TextBody .

Does that help ?

NickHK


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
e Mail attachment La Blonde New Users to Excel 3 April 12th 10 04:05 PM
how to add attachment in a CDO mail Julaf Excel Discussion (Misc queries) 20 August 19th 08 04:36 PM
mail and attachment Jithu Excel Discussion (Misc queries) 1 July 9th 07 12:38 PM
E-Mail attachment to same e-mail address in Outlook Vick Excel Discussion (Misc queries) 4 May 17th 07 07:53 PM
Send mail with attachment Jos Vens Excel Programming 4 October 31st 03 08:13 PM


All times are GMT +1. The time now is 06:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"