Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to send an email with word VBA command button?

12 views
Skip to first unread message

Jeff

unread,
Aug 21, 2007, 3:58:07 PM8/21/07
to
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 "EmailA...@Email.com"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub

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

Jean-Guy Marcil

unread,
Aug 21, 2007, 6:02:06 PM8/21/07
to
Jeff was telling us:
Jeff nous racontait que :

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
jmarci...@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Jeff

unread,
Aug 22, 2007, 8:56:03 AM8/22/07
to
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.

Jean-Guy Marcil

unread,
Aug 26, 2007, 6:22:57 PM8/26/07
to
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.

Jeff

unread,
Aug 28, 2007, 9:02:06 AM8/28/07
to
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.

"Jean-Guy Marcil" wrote:

> 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.

SITCFanTN

unread,
Aug 29, 2007, 11:20:01 AM8/29/07
to
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>

Jeff

unread,
Aug 30, 2007, 3:18:04 PM8/30/07
to
I have found that it doesnt like the other macros in my project. My thats
your problem too.

Jeff

unread,
Aug 30, 2007, 5:20:01 PM8/30/07
to
Try setting the HasRoutingSlip property to False. I think that is causing the
conflict.

Jeff

unread,
Sep 11, 2007, 8:50:02 AM9/11/07
to
I got it. See the code below:

Private Sub CommandButton2_Click()
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "Doc Title"
.AddRecipient "EmailA...@Email.com"
.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.

0 new messages