A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Attach Excel Worksheet (Not Workbook) to Email



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 23rd 09, 06:46 PM posted to microsoft.public.outlook.program_vba
wpiet
external usenet poster
 
Posts: 19
Default Attach Excel Worksheet (Not Workbook) to Email

Is there a way to attach a single worksheet from an Excel workbook to an
Outlook email?
I have a workbook with multiple worksheets, each of which must attach to a
different email. The following code works fine as far as creating & sending
the emails but, for each sheet in the array, I need to attach a copy of the
sheet.
I'm hoping to avoid saving each sheet as a separate workbook but suspect I'm
tilting at windmills.
The "Attachments.Add" line is one of many vain attempts I've made. This one,
as many others, returns Run-time error '438': Object doesn't support this
property or method.

Dim XL As Object
Dim Sht As Worksheet
Dim EmlMsg As MailItem

On Error Resume Next
Set XL = GetObject(, "Excel.Application")

If XL Is Nothing Then
Set XL = CreateObject("Excel.Application")
End If

On Error GoTo 0
XL.Visible = True
XL.Workbooks.Open FileName:="Whatever.xls"

' Send e-mails

For Each Sht In XL.Sheets(Array("OPC", "BP", "WH", "CR", "Oper", "Eng"))
Sht.Activate
Set EmlMsg = CreateItem(0)

With EmlMsg
.To = XL.VLookup(XL.Range("I1"), XL.Range("DstMgrEml"), 2, False)
.Subject = "Something Clever"
.Body = XL.VLookup(XL.Range("I1"), XL.Range("DstMgrEml"), 3,
False) _
& "," & XL.Worksheets("Managers").Range("D8")
.Save
.Attachments.Add XL.Workbook.ActiveSheet
.Send
End With

Set EmlMsg = Nothing
Next Sht

Thanks.
--
Will
Ads
  #2  
Old January 23rd 09, 07:00 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Attach Excel Worksheet (Not Workbook) to Email

As far as I know you will need to save each sheet as a separate workbook,
but you might want to post in an Excel group and see if they have any
suggestions.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"wpiet" wrote in message
...
Is there a way to attach a single worksheet from an Excel workbook to an
Outlook email?
I have a workbook with multiple worksheets, each of which must attach to a
different email. The following code works fine as far as creating &
sending
the emails but, for each sheet in the array, I need to attach a copy of
the
sheet.
I'm hoping to avoid saving each sheet as a separate workbook but suspect
I'm
tilting at windmills.
The "Attachments.Add" line is one of many vain attempts I've made. This
one,
as many others, returns Run-time error '438': Object doesn't support this
property or method.

Dim XL As Object
Dim Sht As Worksheet
Dim EmlMsg As MailItem

On Error Resume Next
Set XL = GetObject(, "Excel.Application")

If XL Is Nothing Then
Set XL = CreateObject("Excel.Application")
End If

On Error GoTo 0
XL.Visible = True
XL.Workbooks.Open FileName:="Whatever.xls"

' Send e-mails

For Each Sht In XL.Sheets(Array("OPC", "BP", "WH", "CR", "Oper",
"Eng"))
Sht.Activate
Set EmlMsg = CreateItem(0)

With EmlMsg
.To = XL.VLookup(XL.Range("I1"), XL.Range("DstMgrEml"), 2,
False)
.Subject = "Something Clever"
.Body = XL.VLookup(XL.Range("I1"), XL.Range("DstMgrEml"), 3,
False) _
& "," & XL.Worksheets("Managers").Range("D8")
.Save
.Attachments.Add XL.Workbook.ActiveSheet
.Send
End With

Set EmlMsg = Nothing
Next Sht

Thanks.
--
Will


  #3  
Old January 23rd 09, 08:35 PM posted to microsoft.public.outlook.program_vba
wpiet
external usenet poster
 
Posts: 19
Default Attach Excel Worksheet (Not Workbook) to Email

Thanks, Ken.
I'll try that.
--
Will


"Ken Slovak - [MVP - Outlook]" wrote:

As far as I know you will need to save each sheet as a separate workbook,
but you might want to post in an Excel group and see if they have any
suggestions.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"wpiet" wrote in message
...
Is there a way to attach a single worksheet from an Excel workbook to an
Outlook email?
I have a workbook with multiple worksheets, each of which must attach to a
different email. The following code works fine as far as creating &
sending
the emails but, for each sheet in the array, I need to attach a copy of
the
sheet.
I'm hoping to avoid saving each sheet as a separate workbook but suspect
I'm
tilting at windmills.
The "Attachments.Add" line is one of many vain attempts I've made. This
one,
as many others, returns Run-time error '438': Object doesn't support this
property or method.

Dim XL As Object
Dim Sht As Worksheet
Dim EmlMsg As MailItem

On Error Resume Next
Set XL = GetObject(, "Excel.Application")

If XL Is Nothing Then
Set XL = CreateObject("Excel.Application")
End If

On Error GoTo 0
XL.Visible = True
XL.Workbooks.Open FileName:="Whatever.xls"

' Send e-mails

For Each Sht In XL.Sheets(Array("OPC", "BP", "WH", "CR", "Oper",
"Eng"))
Sht.Activate
Set EmlMsg = CreateItem(0)

With EmlMsg
.To = XL.VLookup(XL.Range("I1"), XL.Range("DstMgrEml"), 2,
False)
.Subject = "Something Clever"
.Body = XL.VLookup(XL.Range("I1"), XL.Range("DstMgrEml"), 3,
False) _
& "," & XL.Worksheets("Managers").Range("D8")
.Save
.Attachments.Add XL.Workbook.ActiveSheet
.Send
End With

Set EmlMsg = Nothing
Next Sht

Thanks.
--
Will



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reminder from Excel Workbook Looping through Outlook and VBA 1 February 29th 08 06:03 PM
Trying to import from an Excel worksheet Jan Outlook - Using Contacts 6 November 9th 07 02:37 AM
Automate email and attach excel worksheet or workbook wilma2299 Outlook and VBA 3 April 13th 07 07:06 AM
How can I eMail only the selection from Excel, not the workbook Andre Outlook - General Queries 0 February 20th 07 08:46 PM
Outlook contacts list into Excel worksheet? Ed Outlook and VBA 3 February 2nd 07 12:33 AM


All times are GMT +1. The time now is 08:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.