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

Can you help?

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to open
Outlook with code and add the attachment. I don't want to
send or address the email - the user needs to do this.

I tried the following code but it seems to force me to
include the email address and automatically send it.
Don't know what I'm doing wrong. Thank you

Dim OLF As Outlook.MAPIFolder, olMailItem As
Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace
("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail
message
With olMailItem
.Subject = "PDA Request" ' message subject
Set ToContact = .Recipients.Add("email
address.com") ' add a recipient
.Body = "test PDA request" & Chr(13)
' the message text with a line break
.Attachments.Add "P:\PDA\PDA Request shell.xlt",
olByValue, , _
"Attachment" ' insert attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olByReference, , _
"Shortcut to Attachment" ' insert shortcut
' .Attachments.Add "C:\FolderName\Filename.txt",
olEmbeddedItem, , _
"Embedded Attachment" ' embedded attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olOLE, , _
"OLE Attachment" ' OLE attachment
' .OriginatorDeliveryReportRequested = True '
delivery confirmation
' .ReadReceiptRequested = True ' read confirmation
' .Application
.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in the
Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Email from Excel

Hi Cindy

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to open
Outlook with code and add the attachment. I don't want to
send or address the email - the user needs to do this.


the To line is "" and I use Display instead of Send

Sub Mail_workbook_Outlook()
'This example send the last saved version of the Activeworkbook
'You must add a reference to the Microsoft outlook Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add ActiveWorkbook.FullName
'In Excel 97 use ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Can you help?

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to open
Outlook with code and add the attachment. I don't want to
send or address the email - the user needs to do this.

I tried the following code but it seems to force me to
include the email address and automatically send it.
Don't know what I'm doing wrong. Thank you

Dim OLF As Outlook.MAPIFolder, olMailItem As
Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace
("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail
message
With olMailItem
.Subject = "PDA Request" ' message subject
Set ToContact = .Recipients.Add("email
address.com") ' add a recipient
.Body = "test PDA request" & Chr(13)
' the message text with a line break
.Attachments.Add "P:\PDA\PDA Request shell.xlt",
olByValue, , _
"Attachment" ' insert attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olByReference, , _
"Shortcut to Attachment" ' insert shortcut
' .Attachments.Add "C:\FolderName\Filename.txt",
olEmbeddedItem, , _
"Embedded Attachment" ' embedded attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olOLE, , _
"OLE Attachment" ' OLE attachment
' .OriginatorDeliveryReportRequested = True '
delivery confirmation
' .ReadReceiptRequested = True ' read confirmation
' .Application
.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in the
Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Email from Excel

Thanks Ron,

I did find this in an article you must have written.

One more question - when using the activebook.fullname it
requires the workbook to first be saved. I cannot save
the workbook in code because this will be used by many
users and the paths are all different. I tried to trap the
error number but it doesn't remain the same. Any ideas
how I can "trap" that the document isn't saved and prompt
the user to save? Thanks

Cindy
-----Original Message-----
Hi Cindy

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to

open
Outlook with code and add the attachment. I don't want

to
send or address the email - the user needs to do this.


the To line is "" and I use Display instead of Send

Sub Mail_workbook_Outlook()
'This example send the last saved version of the

Activeworkbook
'You must add a reference to the Microsoft outlook Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add ActiveWorkbook.FullName
'In Excel 97 use ActiveWorkbook.Path & "\" &

ActiveWorkbook.Name
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message ...
Can you help?

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to

open
Outlook with code and add the attachment. I don't want

to
send or address the email - the user needs to do this.

I tried the following code but it seems to force me to
include the email address and automatically send it.
Don't know what I'm doing wrong. Thank you

Dim OLF As Outlook.MAPIFolder, olMailItem As
Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace
("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail
message
With olMailItem
.Subject = "PDA Request" ' message subject
Set ToContact = .Recipients.Add("email
address.com") ' add a recipient
.Body = "test PDA request" & Chr(13)
' the message text with a line break
.Attachments.Add "P:\PDA\PDA Request shell.xlt",
olByValue, , _
"Attachment" ' insert attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olByReference, , _
"Shortcut to Attachment" ' insert shortcut
' .Attachments.Add "C:\FolderName\Filename.txt",
olEmbeddedItem, , _
"Embedded Attachment" ' embedded attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olOLE, , _
"OLE Attachment" ' OLE attachment
' .OriginatorDeliveryReportRequested = True '
delivery confirmation
' .ReadReceiptRequested = True ' read

confirmation
' .Application
.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in the
Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing



.

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

Hi Cindy

You can check it like this
If the workbook is not saved the path length is 0

ActiveWorkbook.Save
will prompt the user to save the file

If Len(ActiveWorkbook.Path) = 0 Then
ActiveWorkbook.Save
End If


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Thanks Ron,

I did find this in an article you must have written.

One more question - when using the activebook.fullname it
requires the workbook to first be saved. I cannot save
the workbook in code because this will be used by many
users and the paths are all different. I tried to trap the
error number but it doesn't remain the same. Any ideas
how I can "trap" that the document isn't saved and prompt
the user to save? Thanks

Cindy
-----Original Message-----
Hi Cindy

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to

open
Outlook with code and add the attachment. I don't want

to
send or address the email - the user needs to do this.


the To line is "" and I use Display instead of Send

Sub Mail_workbook_Outlook()
'This example send the last saved version of the

Activeworkbook
'You must add a reference to the Microsoft outlook Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add ActiveWorkbook.FullName
'In Excel 97 use ActiveWorkbook.Path & "\" &

ActiveWorkbook.Name
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message ...
Can you help?

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to

open
Outlook with code and add the attachment. I don't want

to
send or address the email - the user needs to do this.

I tried the following code but it seems to force me to
include the email address and automatically send it.
Don't know what I'm doing wrong. Thank you

Dim OLF As Outlook.MAPIFolder, olMailItem As
Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace
("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail
message
With olMailItem
.Subject = "PDA Request" ' message subject
Set ToContact = .Recipients.Add("email
address.com") ' add a recipient
.Body = "test PDA request" & Chr(13)
' the message text with a line break
.Attachments.Add "P:\PDA\PDA Request shell.xlt",
olByValue, , _
"Attachment" ' insert attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olByReference, , _
"Shortcut to Attachment" ' insert shortcut
' .Attachments.Add "C:\FolderName\Filename.txt",
olEmbeddedItem, , _
"Embedded Attachment" ' embedded attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olOLE, , _
"OLE Attachment" ' OLE attachment
' .OriginatorDeliveryReportRequested = True '
delivery confirmation
' .ReadReceiptRequested = True ' read

confirmation
' .Application
.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in the
Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Email from Excel

Thanks for all your help!
-----Original Message-----
Hi Cindy

You can check it like this
If the workbook is not saved the path length is 0

ActiveWorkbook.Save
will prompt the user to save the file

If Len(ActiveWorkbook.Path) = 0 Then
ActiveWorkbook.Save
End If


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message ...
Thanks Ron,

I did find this in an article you must have written.

One more question - when using the activebook.fullname

it
requires the workbook to first be saved. I cannot save
the workbook in code because this will be used by many
users and the paths are all different. I tried to trap

the
error number but it doesn't remain the same. Any ideas
how I can "trap" that the document isn't saved and

prompt
the user to save? Thanks

Cindy
-----Original Message-----
Hi Cindy

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to

open
Outlook with code and add the attachment. I don't

want
to
send or address the email - the user needs to do

this.

the To line is "" and I use Display instead of Send

Sub Mail_workbook_Outlook()
'This example send the last saved version of the

Activeworkbook
'You must add a reference to the Microsoft outlook

Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add ActiveWorkbook.FullName
'In Excel 97 use ActiveWorkbook.Path & "\" &

ActiveWorkbook.Name
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message ...
Can you help?

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to

open
Outlook with code and add the attachment. I don't

want
to
send or address the email - the user needs to do

this.

I tried the following code but it seems to force me

to
include the email address and automatically send it.
Don't know what I'm doing wrong. Thank you

Dim OLF As Outlook.MAPIFolder, olMailItem As
Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace
("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-

mail
message
With olMailItem
.Subject = "PDA Request" ' message subject
Set ToContact = .Recipients.Add("email
address.com") ' add a recipient
.Body = "test PDA request" & Chr(13)
' the message text with a line break
.Attachments.Add "P:\PDA\PDA Request

shell.xlt",
olByValue, , _
"Attachment" ' insert attachment


' .Attachments.Add "C:\FolderName\Filename.txt",
olByReference, , _
"Shortcut to Attachment" ' insert

shortcut

' .Attachments.Add "C:\FolderName\Filename.txt",
olEmbeddedItem, , _
"Embedded Attachment" ' embedded

attachment

' .Attachments.Add "C:\FolderName\Filename.txt",
olOLE, , _
"OLE Attachment" ' OLE attachment
' .OriginatorDeliveryReportRequested = True '
delivery confirmation
' .ReadReceiptRequested = True ' read

confirmation
' .Application
.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in

the
Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing


.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Email from Excel

I found out how to do this on
http://www.rondebruin.nl/sendmail.htm

Awesome email examples. Thanks!

Cindy
-----Original Message-----
Can you help?

via a command button, I need to be able to email the
workbook on the screen as an attachment. I'd like to

open
Outlook with code and add the attachment. I don't want

to
send or address the email - the user needs to do this.

I tried the following code but it seems to force me to
include the email address and automatically send it.
Don't know what I'm doing wrong. Thank you

Dim OLF As Outlook.MAPIFolder, olMailItem As
Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace
("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail
message
With olMailItem
.Subject = "PDA Request" ' message subject
Set ToContact = .Recipients.Add("email
address.com") ' add a recipient
.Body = "test PDA request" & Chr(13)
' the message text with a line break
.Attachments.Add "P:\PDA\PDA Request shell.xlt",
olByValue, , _
"Attachment" ' insert attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olByReference, , _
"Shortcut to Attachment" ' insert shortcut
' .Attachments.Add "C:\FolderName\Filename.txt",
olEmbeddedItem, , _
"Embedded Attachment" ' embedded attachment
' .Attachments.Add "C:\FolderName\Filename.txt",
olOLE, , _
"OLE Attachment" ' OLE attachment
' .OriginatorDeliveryReportRequested = True '
delivery confirmation
' .ReadReceiptRequested = True ' read confirmation
' .Application
.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in the
Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing
.

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
send email to each customer email in excel sheet. -keevill- Excel Discussion (Misc queries) 3 July 17th 08 02:33 PM
Email addresses in Excel need to format for mass email Boomer Excel Worksheet Functions 1 June 9th 06 01:46 PM
Email editor closes when forwarding Excel-embedded email Bambina Setting up and Configuration of Excel 0 March 16th 06 10:45 PM
working on excel document in email saved changes in email not in . butter Excel Discussion (Misc queries) 2 February 20th 06 09:25 AM
body of email disappears when I send an email from Excel ~A Excel Discussion (Misc queries) 0 February 25th 05 10:55 PM


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