Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    compile error

    Apart from my abject modesty, my only other fault is that I don't understand classes, registering things and so on.

    I'm following the examples from Word97SR2/VBA help files. I tapped the F1 function key on "Application" and followed through the Application Object to the method QuitEvent and set up a class module as requested.

    The final piece of the jigsaw is to register the event class module (whatever that is). The sample code I paste below.

    When I run it I get a compile error "User defined type not defined". I can't see what else I could register that would be useful, so I suspect it's something else.

    Does anyone understand this type of error? I am researching the interesting problem over in Word for the chap who has an attorney who won't save her work .......

    <pre>Sub Register_Event_Handler()
    Dim X As New EventClassModule
    Set X.App = Word.Application
    End Sub
    </pre>


  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: compile error

    Chris,

    Is the class module called "EventClassModule"?

    I have something which performs quite similar, so this is how I set it up (it's probably just about the same as what you have done anyway). This one clears out the form field "Mother's Maiden Name" when the user saves the form:

    .I created a Class Module (Insert, Class Module)

    .I put this code into the class module:
    <pre>Option Explicit

    Public WithEvents App As Word.Application

    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    ActiveDocument.FormFields("MothersMaidenName").Res ult = ""
    End Sub</pre>


    .I named the class module "EventClassModule"

    .I put this code into my AutoNew & AutoOpen:
    <pre>Option Explicit
    Dim X As New EventClassModule

    Sub Main()
    Set X.App = Word.Application
    End Sub
    </pre>


    Don't ask me to explain all of that- that's better done on the <A target="_blank" HREF=http://www.mvps.org/word/FAQs/MacrosVBA/AppClassEvents.htm>mvps site</A>.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: compile error

    Allright. I made three essays:

    1) I changed my Class Module name as you indicated. No luck. Nothing works.

    2) I followed your instructions: Nothing works.

    3) I followed the instructions at the linked site. Nix.


    I believe I am doing something stupid. My events in all instances have a MsgBox, so that I expect AT LEAST to see something pop up before Word Quits, or whatever the event is.

    I beg of you, oh moderator, to take a QUICK look at either/both the attached files and see if they work on your system or see if you can spot something I'm missing.
    Attached Files Attached Files

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: compile error

    Some feedback from 2000: I was not getting events to fire. I looked carefully at the MVPs template, and it put its stuff in a Module rather than ThisDocument. So I cleared out all but Option Explicit from ThisDocument and put this in a new module:

    Public X As New EventClassModule

    Public Sub Autonew()
    MsgBox "In AutoNew"
    Set X.App = Word.Application
    End Sub

    Public Sub autoopen()
    MsgBox "In AutoOpen"
    Set X.App = Word.Application
    End Sub

    Result: DocumentChange and DocumentBeforeSave fire as expected. Quit does not.

    Do these changes have any effect in 97?

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: compile error

    Could you please ask the moderator to trim the width of the code? Thanks - and a great big grin to you, too!

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: compile error

    Thank you for the leg-up, so to speak.

    Attached please find a PKZipped template MVPS.DOT. In the text body of the template you will find (amongst other things) a step-by-step description of what happened with events popping up.

    To date I am unable to trap un-saved documents through the Application.quit event, although I can see that such documents are detectable.

    If I discover any other useful/useable events I'll add them to the template and post them here.
    Attached Files Attached Files

Posting Permissions

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