J
JD
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 = "(e-mail address removed)"
.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
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 = "(e-mail address removed)"
.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