Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Attach Open Excel Spreadshee to Email

I'm trying to send an open spreadsheet as an attachment from code in Outlook
2003. I tried using the excel command SendMail but that triggers a security
warning.

The code fails when I try to add the workbook as an attachment.


Sub temp()

Dim xlApp As New Excel.Application
Dim appwbook As Excel.Workbook
Dim appwsheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set appwbook = xlApp.Workbooks.Add
Set appwsheet = appwbook.Worksheets(1)
xlApp.Visible = True


Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem

Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

objMail.BodyFormat = olFormatHTML
objMail.Recipients.Add ")
objMail.Subject = "this is the subject"

objMail.Attachments.Add (appwbook) ' ** this line doesn't work!!!

objMail.Display

End Sub
--
Billy Rogers

Dallas,TX

Currently Using Office 2000 and Office 2003
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Attach Open Excel Spreadshee to Email

Based on the following, which was copied from Outlook VBA help, looks like
you need the complete path for your Attachments.Add statement.

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\My Documents\Q496.xls", _
olByValue, 1, "4th Quarter 1996 Results Chart"

The last line is the one I was referring to.

"BillyRogers" wrote:

I'm trying to send an open spreadsheet as an attachment from code in Outlook
2003. I tried using the excel command SendMail but that triggers a security
warning.

The code fails when I try to add the workbook as an attachment.


Sub temp()

Dim xlApp As New Excel.Application
Dim appwbook As Excel.Workbook
Dim appwsheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set appwbook = xlApp.Workbooks.Add
Set appwsheet = appwbook.Worksheets(1)
xlApp.Visible = True


Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem

Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

objMail.BodyFormat = olFormatHTML
objMail.Recipients.Add ")
objMail.Subject = "this is the subject"

objMail.Attachments.Add (appwbook) ' ** this line doesn't work!!!

objMail.Display

End Sub
--
Billy Rogers

Dallas,TX

Currently Using Office 2000 and Office 2003

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Attach Open Excel Spreadshee to Email

After reading your post a little closer, I'm not sure you can send an open
file as an attachment. That is probably why you got the security warning
when you tried it from the menu.

"JLGWhiz" wrote:

Based on the following, which was copied from Outlook VBA help, looks like
you need the complete path for your Attachments.Add statement.

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\My Documents\Q496.xls", _
olByValue, 1, "4th Quarter 1996 Results Chart"

The last line is the one I was referring to.

"BillyRogers" wrote:

I'm trying to send an open spreadsheet as an attachment from code in Outlook
2003. I tried using the excel command SendMail but that triggers a security
warning.

The code fails when I try to add the workbook as an attachment.


Sub temp()

Dim xlApp As New Excel.Application
Dim appwbook As Excel.Workbook
Dim appwsheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set appwbook = xlApp.Workbooks.Add
Set appwsheet = appwbook.Worksheets(1)
xlApp.Visible = True


Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem

Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

objMail.BodyFormat = olFormatHTML
objMail.Recipients.Add ")
objMail.Subject = "this is the subject"

objMail.Attachments.Add (appwbook) ' ** this line doesn't work!!!

objMail.Display

End Sub
--
Billy Rogers

Dallas,TX

Currently Using Office 2000 and Office 2003

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Attach Open Excel Spreadshee to Email

Try:

Add a reference to Microsoft Outlook in VBE (Tools References).

Add this function to a module

Function msgA(mySubject, myBody, myTo, myCC, myAttachment)
Dim OutlookApp As Object
Const olMailItem = 0

Set OutlookApp = CreateObject("Outlook.Application")
With OutlookApp.CreateItem(olMailItem)
.Subject = mySubject
.Body = myBody
.To = myTo
.cc = myCC
.Attachments.Add myAttachment
.Send
End With
Set OutlookApp = Nothing
End Function

In your userform, add a button and in the click event add the following
lines:
Subject = "Test"
Body = "Attached Excel file"
A = "
CC = "

msgA Subject, Body, A, CC, ActiveWorkbook.FullName

This is working for me with Excel 2000 pro.

NB. The code snippet is not mine. But I do not remember where I picked
from Internet.

I hope this helps.

Regards,
Karim

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Attach Open Excel Spreadshee to Email

Try:

Add a reference to Microsoft Outlook in VBE (Tools References).

Add this function to a module

Function msgA(mySubject, myBody, myTo, myCC, myAttachment)
Dim OutlookApp As Object
Const olMailItem = 0

Set OutlookApp = CreateObject("Outlook.Application")
With OutlookApp.CreateItem(olMailItem)
.Subject = mySubject
.Body = myBody
.To = myTo
.cc = myCC
.Attachments.Add myAttachment
.Send
End With
Set OutlookApp = Nothing
End Function

In your userform, add a button and in the click event add the following
lines:
Subject = "Test"
Body = "Attached Excel file"
A = "
CC = "

msgA Subject, Body, A, CC, ActiveWorkbook.FullName

This is working for me with Excel 2000 pro.

NB. The code snippet is not mine. But I do not remember where I picked
from Internet.

I hope this helps.

Regards,
Karim



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Attach Open Excel Spreadshee to Email

Try:

Add a reference to Microsoft Outlook in VBE (Tools References).

Add this function to a module

Function msgA(mySubject, myBody, myTo, myCC, myAttachment)
Dim OutlookApp As Object
Const olMailItem = 0

Set OutlookApp = CreateObject("Outlook.Application")
With OutlookApp.CreateItem(olMailItem)
.Subject = mySubject
.Body = myBody
.To = myTo
.cc = myCC
.Attachments.Add myAttachment
.Send
End With
Set OutlookApp = Nothing
End Function

In your userform, add a button and in the click event add the following
lines:

Subject = "Test"
Body = "Attached Excel file"
A = "
CC = "

ActiveWorkbook.Save 'must save before sending

msgA Subject, Body, A, CC, ActiveWorkbook.FullName

This is working for me in Excel 2000 pro.

NB. The code snippet is not mine. But I do not remember where I picked
it from Internet.

I hope this helps.

Regards,
Karim

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Attach Open Excel Spreadshee to Email

JLGWhiz,

It looks like I'm going to have to save each workbook. The sendmail command
will send an open workbook that hasn't been saved but it triggers warnings
which I want to avoid.

Karim--thanks for the suggestion but this code is already in outlook and
there is no userform and I've already tried the attachments.add method. It
looks like it only accepts a path to a workbook.
--
Billy Rogers

Dallas,TX

Currently Using Office 2000 and Office 2003


"JLGWhiz" wrote:

After reading your post a little closer, I'm not sure you can send an open
file as an attachment. That is probably why you got the security warning
when you tried it from the menu.

"JLGWhiz" wrote:

Based on the following, which was copied from Outlook VBA help, looks like
you need the complete path for your Attachments.Add statement.

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\My Documents\Q496.xls", _
olByValue, 1, "4th Quarter 1996 Results Chart"

The last line is the one I was referring to.

"BillyRogers" wrote:

I'm trying to send an open spreadsheet as an attachment from code in Outlook
2003. I tried using the excel command SendMail but that triggers a security
warning.

The code fails when I try to add the workbook as an attachment.


Sub temp()

Dim xlApp As New Excel.Application
Dim appwbook As Excel.Workbook
Dim appwsheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set appwbook = xlApp.Workbooks.Add
Set appwsheet = appwbook.Worksheets(1)
xlApp.Visible = True


Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem

Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

objMail.BodyFormat = olFormatHTML
objMail.Recipients.Add ")
objMail.Subject = "this is the subject"

objMail.Attachments.Add (appwbook) ' ** this line doesn't work!!!

objMail.Display

End Sub
--
Billy Rogers

Dallas,TX

Currently Using Office 2000 and Office 2003

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Attach Open Excel Spreadshee to Email

Try:

Add a reference to Microsoft Outlook in VBE (Tools References).

Add this function to a module

Function msgA(mySubject, myBody, myTo, myCC, myAttachment)
Dim OutlookApp As Object
Const olMailItem = 0

Set OutlookApp = CreateObject("Outlook.Application")
With OutlookApp.CreateItem(olMailItem)
.Subject = mySubject
.Body = myBody
.To = myTo
.cc = myCC
.Attachments.Add myAttachment
.Send
End With
Set OutlookApp = Nothing
End Function

In your userform, add a button and in the click event add the following
lines:

Subject = "Test"
Body = "Attached Excel file"
A = "
CC = "

ActiveWorkbook.Save

msgA Subject, Body, A, CC, ActiveWorkbook.FullName

This is working for me in Excel 2000 pro.

NB. The code snippet is not mine. But I do not remember where I picked
it from Internet.

I hope this helps.

Regards,
Karim

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Attach Open Excel Spreadshee to Email


JLGWhiz wrote:
After reading your post a little closer, I'm not sure you can send an open
file as an attachment. That is probably why you got the security warning
when you tried it from the menu.

"JLGWhiz" wrote:

Based on the following, which was copied from Outlook VBA help, looks like
you need the complete path for your Attachments.Add statement.

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\My Documents\Q496.xls", _
olByValue, 1, "4th Quarter 1996 Results Chart"

The last line is the one I was referring to.

"BillyRogers" wrote:

I'm trying to send an open spreadsheet as an attachment from code in Outlook
2003. I tried using the excel command SendMail but that triggers a security
warning.

The code fails when I try to add the workbook as an attachment.


Sub temp()

Dim xlApp As New Excel.Application
Dim appwbook As Excel.Workbook
Dim appwsheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set appwbook = xlApp.Workbooks.Add
Set appwsheet = appwbook.Worksheets(1)
xlApp.Visible = True


Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem

Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

objMail.BodyFormat = olFormatHTML
objMail.Recipients.Add ")
objMail.Subject = "this is the subject"

objMail.Attachments.Add (appwbook) ' ** this line doesn't work!!!

objMail.Display

End Sub
--
Billy Rogers

Dallas,TX

Currently Using Office 2000 and Office 2003


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
Attach all Open Workbooks to email as separate files? nbaj2k[_25_] Excel Programming 3 August 3rd 06 02:25 PM
Generate PDF from Excel & Attach to Email bobwilson[_10_] Excel Programming 3 April 2nd 06 04:21 PM
How do I attach just one Excel worksheet in an email Fernando Moreno Excel Programming 2 January 11th 06 06:19 PM
How to get an object reference to an ALREADY open excel spreadshee JP Excel Programming 4 January 14th 05 07:19 PM
Open an email and attach my excel file benb Excel Programming 1 December 21st 04 08:20 PM


All times are GMT +1. The time now is 01:01 AM.

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"