Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

How to send an email with word VBA command button?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 21 Aug 2007 20:58 GMT
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 "EmailAddress@Email.com"
   .Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub

What am i doing wrong? I know this should work. HELP!!!
Jean-Guy Marcil - 21 Aug 2007 23:02 GMT
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,
[quoted text clipped - 12 lines]
>
> 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?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jeff - 22 Aug 2007 13:56 GMT
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.

> Jeff was telling us:
> Jeff nous racontait que :
[quoted text clipped - 22 lines]
>
> What Word version?
Jean-Guy Marcil - 26 Aug 2007 23:22 GMT
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.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jeff - 28 Aug 2007 14:02 GMT
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.

> Jeff was telling us:
> Jeff nous racontait que :
[quoted text clipped - 16 lines]
> document. If you have many of them, you can try first by copying everything
> except the last ¶ and see how it goes.
SITCFanTN - 29 Aug 2007 16:20 GMT
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>

> 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.
[quoted text clipped - 19 lines]
> > document. If you have many of them, you can try first by copying everything
> > except the last ¶ and see how it goes.
Jeff - 30 Aug 2007 20:18 GMT
I have found that it doesnt like the other macros in my project. My thats
your problem too.

> 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
[quoted text clipped - 24 lines]
> > > document. If you have many of them, you can try first by copying everything
> > > except the last ¶ and see how it goes.
Jeff - 30 Aug 2007 22:20 GMT
Try setting the HasRoutingSlip property to False. I think that is causing the
conflict.

> 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
[quoted text clipped - 24 lines]
> > > document. If you have many of them, you can try first by copying everything
> > > except the last ¶ and see how it goes.
Jeff - 11 Sep 2007 13:50 GMT
I got it. See the code below:

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

> Try setting the HasRoutingSlip property to False. I think that is causing the
> conflict.
[quoted text clipped - 27 lines]
> > > > document. If you have many of them, you can try first by copying everything
> > > > except the last ¶ and see how it goes.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.