Events with Application Object

H

HONYAKUKA

Word 2003

The &%*$&*% Help files!

I am trying to use events with the Application object. The Help page entitled
"Using Events with the Application Object" has the following as the last step:

***************
Initialize the Declared Object
Before the procedure will run, you must connect the declared object in the
class module (App in this 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.App = Word.Application
End Sub

Run the Register_Event_Handler procedure. After the procedure is run, the App
object in the class module points to the Microsoft Word Application object, and
the event procedures in the class module will run when the events occur.
**************

I copied the above code into an ordinary module.

1. First of all, where do you really put the Dim statement? If you copy/paste
the code as is, the Dim statement ends up above the dividing line, directly
below the "End Sub" line of the previous procedure. This results in a Compile
error.

2. To get things moving, I moved the Dim statement below the "Sub
Register_Event_Handler()" line (i.e to the second line of the code). This
results in the following error: "User-defined type not defined." (For your
reference, the Help page that this leads to is reproduced below.)

MY QUESTION: What steps do I need to take to resolve this error? Which (if
any) of the three choices on the Help page, below, is most appropriate?

Thanks very much.

Jay

**********Help page*************************
User-defined type not defined

You can create your own data types in Visual Basic, but they must be defined
first in a Type...End Type statement or in a properly registered object library
or type library. This error has the following causes and solutions:

- You tried to declare a variable or argument with an undefined data type or
you specified an unknown class or object name.
Use the Type statement in a module to define a new data type. If you are trying
to create a reference to a class, the class must be visible to the project. If
you are referring to a class in your program, you must have a class module of
the specified name in your project. Check the spelling of the type name or name
of the object.

- The type you want to declare is in another module but has been declared
Private.
Move the definition of the type to a standard module where it can be Public.

- The type is a valid type, but the object library or type library in which it
is defined isn't registered in Visual Basic.
Display the References dialog box, and then select the appropriate object
library or type library. For example, if you don't check the Data Access Object
in the References dialog box, types like Database, Recordset, and TableDef
aren't recognized and references to them in code cause this error.

************************
 

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