Eventhandler with COM

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

does anyone know, how i can create an event handler for an COM- object
created with CreateObject ?
For instance, i have the following :
Dim oWordApp As Variant
....
Set oWordApp = CreateObject ("Word.Application")

Now i have to do something within the word's "NewDocument" - event.
If i used an ActiveX control, i would get it with :
Sub oWordApp_NewDocument ()
EndSub

But how to create / assign the eventhandler for my dynamic variant oWordApp
- object ?

Background :
In my Application i use an ActiveX Control for handling a scanner. But only
a few workstation have a scanner. But nevertheless if have to setup the
ActiveX on each computer.
Now i want to use some kind of 'late binding' to avoid compiler failures
while opening the form with the ActiveX - control. I hope, this explains my
problem.

Thanks all
Tino
 
GoogleGroups search on the Access NG's for:
WithEvents Word

There is also an excellent article out there by Ken Getz demonstrating
something similiar to your request. I cannot remember if it is in the MS
KB or the MS Office site.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Thanks Stephen,

i searched and i found something, but one post shows me, than i am wrong :
...."you try to do the impossible"...

If i declare my object as specific class
Dim withevents myObj as ScannerClass

it will work. But there is a problem at the machines with no ScannerClass
installed.

If i declare

Dim withevents myObj as Variant

to hide ScannerClass from the VB Compiler it will not work, as i learned
searching google groups, because VB does'nt know which Interface to query (in
order to serve the eventhandlers to me)

I think, there's no solution.
Thank's at all!
 
In order to use WithEvents you must declare the variable as a specific
class type, you cannot simply use As Variant.
You've got me mixed up now. First you were talking about using with
Events to access the WOrd AUtomation interface and now you are talking
about a "ScannerClass" object.

Anyhow, since you must setup the Scanner ActiveX control on each
workstation, why do you feel you need to use Late Binding?
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Thank You Stephen,
and sorry about my confusing explaination and my terrible english.
Mentioning Word sould be only an example, right, i have to handle with the
Pegasus Imaging TwainPro Scanner Control.
This ActiveX is licensed per seat and we normally need the license only at
the workstations which really have a scanner (today 25). But the application
will run at perhaps 60 machines. Normally we 'distribute' a mde - File an
nobody sould recompile the project at his own machine. Additional, before i
call the form with the ActiveX within, i check if there ist the control
installed (if the dll is present). If not, the user cannot open the form.
Thats my 'workaround'.
But we all know the problems, made by 'lost' libraries. Maybe, i see the
problem tooo complicated; we will know after distibution.
You know : while testing all works fine, but the naturally 'enemy' of the
programmer is the user ;-).
Thanks a lot.
Tino.
 
Back
Top