How to send an email with word VBA command button?

J

Jeff

I am trying to get this to work. I have a commad button i want it to open a
new email message, attach the active document, insert Subject, and recipient.
Much like .send mail. I have tried using the routing slip but word crashes
everytime! Here is an example

Private Sub CommandButton2_Click()
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "Doc Title"
.AddRecipient "(e-mail address removed)"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub

What am i doing wrong? I know this should work. HELP!!!
 
J

Jean-Guy Marcil

Jeff was telling us:
Jeff nous racontait que :
I am trying to get this to work. I have a commad button i want it to
open a new email message, attach the active document, insert Subject,
and recipient. Much like .send mail. I have tried using the routing
slip but word crashes everytime! Here is an example

Private Sub CommandButton2_Click()
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "Doc Title"
.AddRecipient "(e-mail address removed)"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub

What am i doing wrong? I know this should work. HELP!!!

Where is the command button?
On the page, in a userform, elsewhere?

What is the document content?

What Word version?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jeff

The Command button is on the page. The document is a survey like form i would
like to have emailed to a specific person. I am using Word 2002.
 
J

Jean-Guy Marcil

Jeff was telling us:
Jeff nous racontait que :
The Command button is on the page. The document is a survey like form
i would like to have emailed to a specific person. I am using Word
2002.

I just tested your code as is on a protected document (for forms) and it did
work as excepted.

I do not have access to my 2002 machine right now though...

Can you try your document on Word 2003 and see if it crashes as well?

If it does, there is probably something corrupted in your template. You will
need to rebuild it from a fresh document.
You can try copying all of it except the last ¶ and any section breaks. It
is safer to recreate the section breaks when trying to recreate a corrupted
document. If you have many of them, you can try first by copying everything
except the last ¶ and see how it goes.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jeff

You are absolutly right. The code works fine on its own. I have tried on Win
XP & Vista it works on both. I think it's a local issue. Thanks for your help.
 
S

SITCFanTN

This code worked great for me this morning on my document, now it errors out
every time I click the command button. I have made no changes. any
suggestions on why it would work for days and then just errror out even when
no changes have been made>
 
J

Jeff

I have found that it doesnt like the other macros in my project. My thats
your problem too.
 
J

Jeff

Try setting the HasRoutingSlip property to False. I think that is causing the
conflict.
 
J

Jeff

I got it. See the code below:

Private Sub CommandButton2_Click()
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
..Subject = "Doc Title"
..AddRecipient "(e-mail address removed)"
..Delivery = wdAllAtOnce
End With
ActiveDocument.Route
ActiveDocument.HasRoutingSlip = False
End Sub
You have to tell VBA to reset the Routing slip property to false to get
this to work everytime.
 

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