Adding a button to Automaticaly E-mail a Word Document?

N

Neil

Hi there,

im want to make a word document with fields for users to fill out, then
press a button at the bottom, and the document will email to a specified
email address' (within the programming) and then close the document. - the
document will be opened from an email.

if anyone can tell me how to achieve this, that would be great,

thanks,

Neil
 
C

Chuck

Create your button on your document, double click on it to bring up the VBE
and in the CommandButton_Click event use the following

Private Sub CommandButton1_Click()

'Erase any previous routing info
ActiveDocument.HasRoutingSlip = False

'Set new routing info
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Reset
.AddRecipient Recipient:="(e-mail address removed)"
.Message = "Your message here"
.ReturnWhenDone = False
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route

End Sub
 
N

Neil

Hi chuck,

thanks for your reply - ive tried adding the code to a button in my
document, but it is giving me a message advising it is trying to access
contacts in my address book - which i dont think i want it to do, i just want
it to send to my specified address (which i specified) - when i click cancel,
it then has a run time error.

any ideas?

many thanks,

Neil
 
C

Chuck

It's not trying to access your address book because the address is hard coded
in the code (whatever you put in for "(e-mail address removed)"). Note that the
dialog you get says "if this is unexpected it may be a virus ...". Of course
it's not unexpected -- it's in the code you've run.

The alternative would be to use ActiveDocument.SendMail but I don't know of
a way to get the email address into the To field of the mail message without
using SendKeys, but I've tried it and SendKeys doesn't seem to work in this
scenario (at least in Word2000 and Outlook2000).

So unless someone else has a suggestion you may have to live with the
security warning you get with Route or else have the user supply the email
address using SendMail.
 
C

Chuck

I should have said _it doesn't matter if_ it's trying to access your address
book...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top