Using Events with the Application Object

L

LEU

I was looking in the help and it said the following:

Before the procedure will run, you must connect the declared object in the
class module (wdApp in my example) with the Application object. You can do
this with the following code from any module.

Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.wdApp = Word.Application
End Sub

When I debug I get the following error: User-defined type not defined
and it points tothe following: Dim X As New EventClassModule

What am I doing wrong.
 
J

Jay Freedman

The answer is buried in the text of the help topic, under the heading
"Declare the Object Variable":

"For example, assume that a new class module is created and called
EventClassModule."

If you created a new class module, by default it is named Class1, and
you have to either rename it (in the Properties pane) to
EventClassModule, or else change the module code to

Dim X As New Class1

to match the default name.

Bill Coan was more explicit about this step in his article at
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm.
 
D

Dave D-C

Leu,
And the help says
"For example, assume that a new class module is created and called
EventClassModule. "
So "EventClassModule" is the class module name,
not a reserved word.

D-C Dave
 
L

LEU

Thanks all 3 of you for the information. I now know how this works. I made
the changes and it almost works . I am having problem with the autoexec macro
to get it to work, but I'll post it as a new question.

LEU
 

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