Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Macro button in MS Word...

Status
Not open for further replies.

bddewell408

Technical User
Jul 25, 2003
56
US
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
 
BTW, I am using MS Word 97, and Outlook 2002, if that makes any difference
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top