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