Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Omaha, Nebraska, USA
    Thanked 0 Times in 0 Posts

    Canceling a close (Word 2000 SR1)

    How do you cancel a document close from the auto close macro? I have a field that needs to have an entry in it before the document can be closed. If the user tries to close the document or word without an entry in the field, I want to cancel the close an put focus back in the field.

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Eugene, Oregon, USA
    Thanked 0 Times in 0 Posts

    Re: Canceling a close (Word 2000 SR1)

    I don't think you can do this using an AutoClose macro; I think you will need to build a class module to access a DocumentBeforeClose event that will give you a cancel parameter.

    If you haven't ever done this....

    Creating a class module is as simple as clicking the menu item under the "Insert" menu in the VBE. Your class module must then declare a public variable using the "WithEvents" keyword for the word application; this allows you to capture the DocumentBeforeClose event which, in turn, has a "Cancel" parameter that allows you to return to the document.

    For example, your class module may look something like....

    Public WithEvents App As Word.Application

    Private Sub App_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    'do something here
    Exit Sub
    Cancel = True
    End Sub

    In order to activate your class module, you need to instantiate (reference) your class module in a normal code module. To do this, you will need to do two things:

    (1) In the general declarations section of your class module, you will need to declare an object variable for your class module.
    Private objX As New [NameOfYourClassModule]

    (2) You will need to run some code to connect your object variable to the "App" application variable in your class module. Something like...

    Sub AutoExec()
    Set objX.App = Word.Application
    End Sub

    If this isn't clear, post back and I'll try to clarify.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts