bddewell408
Technical User
I have created a button in the toolbar that runs the below code. The purpose of this macro button is to send the MS Word document that is currently open via outlook email to a particular address . When the following line is Remmed out, it send the email like it should, when the following line is active, I get an error message (below code line)
.attachments = "C:\Documents and Settings\DewellBD\Desktop\Registration form.doc"
Run-time error '-2147352567 (80020009)':
The operation failed
I am hoping the MS Word document does not have to be closed to send the form. BTW, I am not a programmer and copied this code from the FAQ on this page.
Entire Code
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 01/20/2005 by joycej
'
Dim olApp As Object
Dim subject As String
Dim olMailItem
Dim newMail
Dim newRecipient
Dim mailBody As String
Dim strAddress As String
subject = "Training Application"
mailBody = "Training Application"
strAddress = "DewellBD@test.gov"
Set olApp = CreateObject("Outlook.Application")
Set newMail = olApp.CreateItem(olMailItem)
Set newRecipient = newMail.Recipients.Add(strAddress)
With newMail
.subject = subject
.body = mailBody
.attachments = "C:\Documents and Settings\DewellBD\Desktop\Registration form.doc"
End With
newMail.Send
olApp.Quit
Set olApp = Nothing
Set newMail = Nothing
Set newRecipient = Nothing
End Sub
Thanks in advance for the help
.attachments = "C:\Documents and Settings\DewellBD\Desktop\Registration form.doc"
Run-time error '-2147352567 (80020009)':
The operation failed
I am hoping the MS Word document does not have to be closed to send the form. BTW, I am not a programmer and copied this code from the FAQ on this page.
Entire Code
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 01/20/2005 by joycej
'
Dim olApp As Object
Dim subject As String
Dim olMailItem
Dim newMail
Dim newRecipient
Dim mailBody As String
Dim strAddress As String
subject = "Training Application"
mailBody = "Training Application"
strAddress = "DewellBD@test.gov"
Set olApp = CreateObject("Outlook.Application")
Set newMail = olApp.CreateItem(olMailItem)
Set newRecipient = newMail.Recipients.Add(strAddress)
With newMail
.subject = subject
.body = mailBody
.attachments = "C:\Documents and Settings\DewellBD\Desktop\Registration form.doc"
End With
newMail.Send
olApp.Quit
Set olApp = Nothing
Set newMail = Nothing
Set newRecipient = Nothing
End Sub
Thanks in advance for the help