#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Email help

Hi
I am experimenting with Ron de Bruin's "Sending mail from Excel with
CDO" and so far it has worked.


With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Andrew"" "
.Subject = "Progress Report"
.TextBody = strbody

"The line below caused an error"
.addattachment ThisWorkbook.Sheets(2)

"The line below worked"
'.addattachment "C:\Users\Andrew\Desktop\Email example that
works.xls"

.Send
End With



I would like to be able to email a worksheet from the current active
workbook and I tried the line below

..addattachment ThisWorkbook.Sheets(2)

but it gave a type mismatch error.


Help on this greatly appreciated please.

Andrew B
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Email help

The full path is required for attachments.


"Andrew Bourke" wrote in message
...
Hi
I am experimenting with Ron de Bruin's "Sending mail from Excel with CDO"
and so far it has worked.


With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Andrew"" "
.Subject = "Progress Report"
.TextBody = strbody

"The line below caused an error"
.addattachment ThisWorkbook.Sheets(2)

"The line below worked"
'.addattachment "C:\Users\Andrew\Desktop\Email example that
works.xls"

.Send
End With



I would like to be able to email a worksheet from the current active
workbook and I tried the line below

.addattachment ThisWorkbook.Sheets(2)

but it gave a type mismatch error.


Help on this greatly appreciated please.

Andrew B



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Email help

Hi Andrew,

You need to save the worksheet to a separate workbook. There is an example
at the following link.

http://www.vbaexpress.com/kb/getarticle.php?kb_id=326


--
Regards,

OssieMac


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Email help

JLGWhiz wrote:
The full path is required for attachments.


"Andrew Bourke" wrote in message
...
Hi
I am experimenting with Ron de Bruin's "Sending mail from Excel with CDO"
and so far it has worked.


With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Andrew"" "
.Subject = "Progress Report"
.TextBody = strbody

"The line below caused an error"
.addattachment ThisWorkbook.Sheets(2)

"The line below worked"
'.addattachment "C:\Users\Andrew\Desktop\Email example that
works.xls"

.Send
End With



I would like to be able to email a worksheet from the current active
workbook and I tried the line below

.addattachment ThisWorkbook.Sheets(2)

but it gave a type mismatch error.


Help on this greatly appreciated please.

Andrew B




Hi
Thanks for the response - I'm still not sure how to insert the full path
name for the worksheet.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Email help

something i threw together, i think it will work enough to give you an idea.
it will create a new workbook with whatever is on sheet1, save it to the
same path as your existing workbook, load outlook and attach it.

you can fill in variables in the code to fill the various fields outlook.



Option Explicit
Sub test()
Dim ws3 As Worksheet
Dim wb As Workbook
Dim wbNew As Workbook
Dim ws4 As Worksheet
Dim fPath As String
Dim FName As String
Dim OutApp As Object
Dim OutMail As Object
Dim strBody As String

Dim NewSheet As Worksheet
Set wb = ThisWorkbook
Set wb = ThisWorkbook
Set ws4 = wb.Worksheets("Sheet1")

strBody = "This is a test."
fPath = ThisWorkbook.Path & "\"
FName = "Your File Name.xls"
ws4.Copy

ActiveWorkbook.SaveAs Filename:=fPath & FName,
ReadOnlyRecommended:=False
Set wbNew = ActiveWorkbook
wbNew.ActiveSheet.Name = "Summary"

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Your Subject"
.Body = strBody
.Attachments.Add fPath & FName
.Display
End With

Xit:
Set OutMail = Nothing
Set OutApp = Nothing
End Sub




--


Gary Keramidas
Excel 2003


"Andrew Bourke" wrote in message
...
Hi
I am experimenting with Ron de Bruin's "Sending mail from Excel with CDO"
and so far it has worked.


With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Andrew"" "
.Subject = "Progress Report"
.TextBody = strbody

"The line below caused an error"
.addattachment ThisWorkbook.Sheets(2)

"The line below worked"
'.addattachment "C:\Users\Andrew\Desktop\Email example that
works.xls"

.Send
End With



I would like to be able to email a worksheet from the current active
workbook and I tried the line below

.addattachment ThisWorkbook.Sheets(2)

but it gave a type mismatch error.


Help on this greatly appreciated please.

Andrew B




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Email help

There is a code example for the activeworkbook / or worksheet on my CDO page
http://www.rondebruin.nl/cdo.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Andrew Bourke" wrote in message ...
Hi
I am experimenting with Ron de Bruin's "Sending mail from Excel with
CDO" and so far it has worked.


With iMsg
Set .Configuration = iConf
.To = "
.CC = ""
.BCC = ""
.From = """Andrew"" "
.Subject = "Progress Report"
.TextBody = strbody

"The line below caused an error"
.addattachment ThisWorkbook.Sheets(2)

"The line below worked"
'.addattachment "C:\Users\Andrew\Desktop\Email example that
works.xls"

.Send
End With



I would like to be able to email a worksheet from the current active
workbook and I tried the line below

.addattachment ThisWorkbook.Sheets(2)

but it gave a type mismatch error.


Help on this greatly appreciated please.

Andrew B

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Email help

Thanks Ron - I've managed to get it to work!


Ron de Bruin wrote:
There is a code example for the activeworkbook / or worksheet on my CDO
page
http://www.rondebruin.nl/cdo.htm

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Email help

Thanks for that - I will give it a try.


Gary Keramidas wrote:
something i threw together, i think it will work enough to give you an
idea. it will create a new workbook with whatever is on sheet1, save it
to the same path as your existing workbook, load outlook and attach it.

you can fill in variables in the code to fill the various fields outlook.



Option Explicit
Sub test()
Dim ws3 As Worksheet
Dim wb As Workbook
Dim wbNew As Workbook
Dim ws4 As Worksheet
Dim fPath As String
Dim FName As String
Dim OutApp As Object
Dim OutMail As Object
Dim strBody As String

Dim NewSheet As Worksheet
Set wb = ThisWorkbook
Set wb = ThisWorkbook
Set ws4 = wb.Worksheets("Sheet1")

strBody = "This is a test."
fPath = ThisWorkbook.Path & "\"
FName = "Your File Name.xls"
ws4.Copy

ActiveWorkbook.SaveAs Filename:=fPath & FName,
ReadOnlyRecommended:=False
Set wbNew = ActiveWorkbook
wbNew.ActiveSheet.Name = "Summary"

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Your Subject"
.Body = strBody
.Attachments.Add fPath & FName
.Display
End With

Xit:
Set OutMail = Nothing
Set OutApp = Nothing
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
Using Macro how to create email link for the email addresses in aRange or Selection Satish[_2_] Excel Worksheet Functions 8 December 28th 09 03:30 PM
Prompt the start of an email...user fills in email address gab1972 Excel Programming 2 July 16th 09 03:35 PM
Excel VBA macro to send email attachment from default email client wifigoo Excel Programming 2 April 12th 08 03:54 PM
how do you email a portion of a worksheet (range) as an insert into the body of an email? Bruce[_2_] Excel Programming 3 May 31st 07 10:37 PM
Transfer Email addresses from spreadsheet to email address book Beana Excel Discussion (Misc queries) 2 May 30th 06 06:07 PM


All times are GMT +1. The time now is 04:58 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"