Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JD JD is offline
external usenet poster
 
Posts: 1
Default Emailing with Attachment from Excel

I have code to send an email but I would like it to send
the cuurent file, i.e. I want the user to fill in some
data then hit a button to email me the file.

I can get the email piece to work but I'm having trouble
getting any attachment let alone the current file to go
with the email.

I get a runtime error when it gets to the attachment part.

here's the code (trying to pull a file from my hard drive
as a test, I have tried many things, this is one version.


Sub Send_Msg()
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
Set myOlapp = CreateObject("Outlook.Application")
Set myItem = myOlapp.CreateItem(olMailItem)
myItem.Save
Set myAttachments = myItem.Attachments
myAttachments.Add "c:\program files\2002profiles.xls", _
olByValue, 1, "text associated"

With objMail
.To = "
.Subject = "Subject text"
.Body = "This a test of the automated Schedule from
Excel. " & _
"Here is the test group rates: "
.Attachments = ("myattachments")
.Display
.SaveSentMessageFolder = True

End With
Set objMail = Nothing
Set objOL = Nothing
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Emailing with Attachment from Excel

JD,

This isn't the way I use Outlook, but this version seemed to work for me.
You were startuing 2 Outlook sessions, unnecesary, and you trid adding the
attachment after you had alraedy added it. Anyway, try it.

Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
Dim myAttachments

Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
Set myAttachments = objMail.Attachments
myAttachments.Add ActiveWorkbook.FullName, _
olByValue, 1, "text associated"

With objMail
.To = "
.Subject = "Subject text"
.Body = "This a test of the automated Schedule from Excel. " & _
"Here is the test group rates: "
.Display
.SaveSentMessageFolder = True

End With
Set objMail = Nothing
Set objOL = Nothing
End Sub

--

HTH

Bob Phillips

"JD" wrote in message
...
I have code to send an email but I would like it to send
the cuurent file, i.e. I want the user to fill in some
data then hit a button to email me the file.

I can get the email piece to work but I'm having trouble
getting any attachment let alone the current file to go
with the email.

I get a runtime error when it gets to the attachment part.

here's the code (trying to pull a file from my hard drive
as a test, I have tried many things, this is one version.


Sub Send_Msg()
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
Set myOlapp = CreateObject("Outlook.Application")
Set myItem = myOlapp.CreateItem(olMailItem)
myItem.Save
Set myAttachments = myItem.Attachments
myAttachments.Add "c:\program files\2002profiles.xls", _
olByValue, 1, "text associated"

With objMail
.To = "
.Subject = "Subject text"
.Body = "This a test of the automated Schedule from
Excel. " & _
"Here is the test group rates: "
.Attachments = ("myattachments")
.Display
.SaveSentMessageFolder = True

End With
Set objMail = Nothing
Set objOL = Nothing
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Emailing with Attachment from Excel

JD

Here's some more example code for sending with attachments:

"JD" wrote in message
...
I have code to send an email but I would like it to send
the cuurent file, i.e. I want the user to fill in some
data then hit a button to email me the file.

I can get the email piece to work but I'm having trouble
getting any attachment let alone the current file to go
with the email.

I get a runtime error when it gets to the attachment part.

here's the code (trying to pull a file from my hard drive
as a test, I have tried many things, this is one version.


Sub Send_Msg()
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
Set myOlapp = CreateObject("Outlook.Application")
Set myItem = myOlapp.CreateItem(olMailItem)
myItem.Save
Set myAttachments = myItem.Attachments
myAttachments.Add "c:\program files\2002profiles.xls", _
olByValue, 1, "text associated"

With objMail
.To = "
.Subject = "Subject text"
.Body = "This a test of the automated Schedule from
Excel. " & _
"Here is the test group rates: "
.Attachments = ("myattachments")
.Display
.SaveSentMessageFolder = True

End With
Set objMail = Nothing
Set objOL = 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
Hyperlinks don't work when emailing attachment DG Excel Discussion (Misc queries) 6 May 27th 09 07:26 PM
Problems emailing attachment from Excel scrapper777 Excel Discussion (Misc queries) 3 October 30th 07 07:54 PM
Emailing from within Excel Reggiee Excel Discussion (Misc queries) 0 October 1st 07 09:29 AM
Hypoerlink to a Local file and emailing the file as an attachment JohnH Excel Discussion (Misc queries) 0 January 2nd 07 06:45 PM
why does a workwook increase in size when emailing as attachment paula Excel Discussion (Misc queries) 1 July 20th 05 05:35 AM


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