Stop an event

R

Roger

I would like to stop an event in Word VBA. How can I do it?

For example:

Private Sub Document_New()
msgbox("You can't create a new document")
' Now I would like that:
' nothing happens and the new document
' doesn't appear on the screen.
End Sub

Thanks in advance

Roger
 
T

Tushar Mehta

First of all, I don't see how you can use the Document_New event
procedure to do what you want. You will have to use the application
level NewDocument Event. See the Word VBA help for more.

Also, you will have to test to see which, if any, of the following
suggestions work. Use something like ActiveDocument.Close or Documents
(Documents.Count).Close? This, of course, assumes that creating a new
document doesn't trigger other activities...

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
R

Roger

Thanks for your suggestions, but the problem is not so simple.
Another example:

The following procedure is executed before printing:

Private Sub
AppThatLooksInsideThisEventHandler_DocumentBeforePrint(ByVal
Doc As Document, Cancel As Boolean)
MsgBox("You can't print!")
' When the user presses the 'OK' button word prints the
document.
' I would like that nothing happens. How can I do this?
End Sub

Thank you!

Roger
 
T

Tushar Mehta

Have you checked the documentation on the DocumentBeforePrint event?
What does it say about the different parameters?

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

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