Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Email question - Ron deBruin

Hi Ron. I grabbed the below code from your website regarding e-mailing a
sheet from a workbook as an atachment using the CDO method. Grabbing the
sheet and saving it to a location works great. But when the atachment is
e-mailed, the sheet looks strange, and I get an excel error when I try to
open the attachment
"Errors were detected in file 'C:\folder\filename\.xls'
The following is a list of repairs:

Damage to the file was so extensive that repairs were not possible. Excel
attempted to recover your formulas and values, but some data may have been
lost or corrupted."

Any idea why it's doing that? Thanks!

Sub CDO_Send_ActiveSheet()' This example use late binding, you don't have to
set a reference' You must be online when you run the sub Dim iMsg As
Object
Dim iConf As Object
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim WBname As String
' Dim Flds As Variant Application.ScreenUpdating = False
Set WB1 = ActiveWorkbook
ActiveSheet.Copy
'Other possibility's are
'Sheets("Sheet3").Copy
'Sheets(Array("Sheet1", "Sheet3")).Copy
Set WB2 = ActiveWorkbook WBname = "Part of " & WB1.Name & " " &
Format(Now, "dd-mm-yy h-mm-ss") & ".xls"
WB2.SaveAs "C:/" & WBname
' It will save the new file with the ActiveSheet in C:/ with a Date and
Time stamp
WB2.Close False 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") = "Fill
in your SMTP server here"
'
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With 'Check out the Tips section if you want to change the
..To and .TextBody
With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Ron"" "
.Subject = "This is a test"
.TextBody = "Hi there"
.AddAttachment "C:/" & WBname
' You can add any file you want with this line .AddAttachment
"C:/Test.txt"
.Send
End With Kill "C:/" & WBname 'If you not want to delete the file
you send delete this line
Set iMsg = Nothing
Set iConf = Nothing
Set WB1 = Nothing
Set WB2 = Nothing
Application.ScreenUpdating = True
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Email question - Ron deBruin

Hi Steph

Have you remove this line in your test macro
..TextBody = "Hi there"

If you do that you can't open the file
This is a bug in CDO


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Steph" wrote in message ...
Hi Ron. I grabbed the below code from your website regarding e-mailing a
sheet from a workbook as an atachment using the CDO method. Grabbing the
sheet and saving it to a location works great. But when the atachment is
e-mailed, the sheet looks strange, and I get an excel error when I try to
open the attachment
"Errors were detected in file 'C:\folder\filename\.xls'
The following is a list of repairs:

Damage to the file was so extensive that repairs were not possible. Excel
attempted to recover your formulas and values, but some data may have been
lost or corrupted."

Any idea why it's doing that? Thanks!

Sub CDO_Send_ActiveSheet()' This example use late binding, you don't have to
set a reference' You must be online when you run the sub Dim iMsg As
Object
Dim iConf As Object
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim WBname As String
' Dim Flds As Variant Application.ScreenUpdating = False
Set WB1 = ActiveWorkbook
ActiveSheet.Copy
'Other possibility's are
'Sheets("Sheet3").Copy
'Sheets(Array("Sheet1", "Sheet3")).Copy
Set WB2 = ActiveWorkbook WBname = "Part of " & WB1.Name & " " &
Format(Now, "dd-mm-yy h-mm-ss") & ".xls"
WB2.SaveAs "C:/" & WBname
' It will save the new file with the ActiveSheet in C:/ with a Date and
Time stamp
WB2.Close False 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") = "Fill
in your SMTP server here"
'
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With 'Check out the Tips section if you want to change the
.To and .TextBody
With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Ron"" "
.Subject = "This is a test"
.TextBody = "Hi there"
.AddAttachment "C:/" & WBname
' You can add any file you want with this line .AddAttachment
"C:/Test.txt"
.Send
End With Kill "C:/" & WBname 'If you not want to delete the file
you send delete this line
Set iMsg = Nothing
Set iConf = Nothing
Set WB1 = Nothing
Set WB2 = Nothing
Application.ScreenUpdating = True
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Email question - Ron deBruin

That did it. Thanks Ron!!!

"Ron de Bruin" wrote in message
...
Hi Steph

Have you remove this line in your test macro
.TextBody = "Hi there"

If you do that you can't open the file
This is a bug in CDO


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Steph" wrote in message

...
Hi Ron. I grabbed the below code from your website regarding e-mailing

a
sheet from a workbook as an atachment using the CDO method. Grabbing

the
sheet and saving it to a location works great. But when the atachment

is
e-mailed, the sheet looks strange, and I get an excel error when I try

to
open the attachment
"Errors were detected in file 'C:\folder\filename\.xls'
The following is a list of repairs:

Damage to the file was so extensive that repairs were not possible.

Excel
attempted to recover your formulas and values, but some data may have

been
lost or corrupted."

Any idea why it's doing that? Thanks!

Sub CDO_Send_ActiveSheet()' This example use late binding, you don't

have to
set a reference' You must be online when you run the sub Dim iMsg As
Object
Dim iConf As Object
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim WBname As String
' Dim Flds As Variant Application.ScreenUpdating = False
Set WB1 = ActiveWorkbook
ActiveSheet.Copy
'Other possibility's are
'Sheets("Sheet3").Copy
'Sheets(Array("Sheet1", "Sheet3")).Copy
Set WB2 = ActiveWorkbook WBname = "Part of " & WB1.Name & " " &
Format(Now, "dd-mm-yy h-mm-ss") & ".xls"
WB2.SaveAs "C:/" & WBname
' It will save the new file with the ActiveSheet in C:/ with a Date

and
Time stamp
WB2.Close False 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") =

"Fill
in your SMTP server here"
'
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =

25
' .Update
' End With 'Check out the Tips section if you want to change

the
.To and .TextBody
With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Ron"" "
.Subject = "This is a test"
.TextBody = "Hi there"
.AddAttachment "C:/" & WBname
' You can add any file you want with this line .AddAttachment
"C:/Test.txt"
.Send
End With Kill "C:/" & WBname 'If you not want to delete the

file
you send delete this line
Set iMsg = Nothing
Set iConf = Nothing
Set WB1 = Nothing
Set WB2 = Nothing
Application.ScreenUpdating = True
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Email question - Ron deBruin

You can use this also if you don't want to have text in the body

..TextBody = ""


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Steph" wrote in message ...
That did it. Thanks Ron!!!

"Ron de Bruin" wrote in message
...
Hi Steph

Have you remove this line in your test macro
.TextBody = "Hi there"

If you do that you can't open the file
This is a bug in CDO


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Steph" wrote in message

...
Hi Ron. I grabbed the below code from your website regarding e-mailing

a
sheet from a workbook as an atachment using the CDO method. Grabbing

the
sheet and saving it to a location works great. But when the atachment

is
e-mailed, the sheet looks strange, and I get an excel error when I try

to
open the attachment
"Errors were detected in file 'C:\folder\filename\.xls'
The following is a list of repairs:

Damage to the file was so extensive that repairs were not possible.

Excel
attempted to recover your formulas and values, but some data may have

been
lost or corrupted."

Any idea why it's doing that? Thanks!

Sub CDO_Send_ActiveSheet()' This example use late binding, you don't

have to
set a reference' You must be online when you run the sub Dim iMsg As
Object
Dim iConf As Object
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim WBname As String
' Dim Flds As Variant Application.ScreenUpdating = False
Set WB1 = ActiveWorkbook
ActiveSheet.Copy
'Other possibility's are
'Sheets("Sheet3").Copy
'Sheets(Array("Sheet1", "Sheet3")).Copy
Set WB2 = ActiveWorkbook WBname = "Part of " & WB1.Name & " " &
Format(Now, "dd-mm-yy h-mm-ss") & ".xls"
WB2.SaveAs "C:/" & WBname
' It will save the new file with the ActiveSheet in C:/ with a Date

and
Time stamp
WB2.Close False 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") =

"Fill
in your SMTP server here"
'
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =

25
' .Update
' End With 'Check out the Tips section if you want to change

the
.To and .TextBody
With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Ron"" "
.Subject = "This is a test"
.TextBody = "Hi there"
.AddAttachment "C:/" & WBname
' You can add any file you want with this line .AddAttachment
"C:/Test.txt"
.Send
End With Kill "C:/" & WBname 'If you not want to delete the

file
you send delete this line
Set iMsg = Nothing
Set iConf = Nothing
Set WB1 = Nothing
Set WB2 = Nothing
Application.ScreenUpdating = True
End Sub








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
Ron DeBruin Macro - Moving Sheet Name from Last Column to Column A ScottMSP Excel Worksheet Functions 7 December 12th 08 06:07 PM
Calendar drop down ala Ron DeBruin in Excel 2003 Rich D Excel Discussion (Misc queries) 6 July 28th 08 06:25 PM
Sending e-mail - Ron deBruin Steph[_3_] Excel Programming 0 September 20th 04 10:08 PM
email question tiptop[_6_] Excel Programming 1 July 27th 04 06:20 AM
Email question olly Excel Programming 1 July 11th 03 03:17 PM


All times are GMT +1. The time now is 04:12 PM.

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

About Us

"It's about Microsoft Excel"