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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA email VB Form MS Word MailEnvelope

Status
Not open for further replies.

dprayner

Programmer
Oct 14, 2002
140
US
Hi people. I got this code from a MS help file. It seems to work fine when run from a command button on the Word Document, but the same code comes up with an error on the .Send line when run from a command button on a VB form.

Private Sub CommandButton1_Click()
'Use a With...End With block to reference the msoEnvelope object.
With Application.ActiveDocument.MailEnvelope

'Add some introductory text before the body of the e-mail message.
.Introduction = "Please read this and send me your comments."

'Return a MailItem object that you can use to send the document.
With .Item

'All of the mail item settings are saved with the document.
'When you add a recipient to the Recipients collection
'or change other properties these settings will persist.

.Recipients.Add "someone@somewhere.com"
.Subject = "Here is the document."

'The body of this message will be
'the content of the active document.
.Send
End With
End With
End Sub

Both command buttons email, but the form comes up with an error and the message: You cannot close Microsoft Office Word because a dialog box is open. Click OK, switch to Word, and close the dialog box.

This is all the code. I don't have any Unload or Application.Quit commands.

What do you think? DAVE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top