Hi, I consider myself a newbie to vbscript. Been working with VBA for a bit
however. I'm trying to see if I can interact with applications using event
based code. An example of such is:

'Snip******************************
Option Explicit
Dim objExcel
Dim i
Set objExcel = CreateObject("Excel.Application")
WScript.ConnectObject objExcel,"objExcel_"
objExcel.Visible = True
objExcel.Workbooks.Add
i = 0
Do
WScript.Sleep(100)
i = i + 1
Loop While (i < 100)
WScript.Echo("Script Complete")

Sub objExcel_WindowActivate()
WScript.Echo("WindowActivate")
End Sub
'Snip******************************

I tried referencing some of the articles in the library, but I think I wound
up confusing myself. The above code just returns an error that it can not
connect to the object. If I use WScript.CreateObject("Excel.Application",
"objExcel_") instead, it compiles, but does not respond to events. Any
pointers for a newbie?

-J

Re: scripting (Excel) events by mr_unreliable

mr_unreliable
Fri Apr 29 12:52:17 CDT 2005

hi Jesse,

There is (apparently) more to xl events than "meets-the-eye".

After a little searching, I turned up this:

"Event Procedures In Microsoft® Excel97"

found here:

http://www.cpearson.com/excel/events.htm

Taken at face value, it looks like it is tricky to detect
XL events, even if you are programming in XL itself.

Maybe the current version of XL is not as tricky, but then
again, it probably is.

I suspect that if you want to detect XL events, you are
going to have to do some VBA programming, as described in
the above article, and then pass out the event notifications
to your script yourself.

cheers, jw



jessealbert wrote:
> Hi, I consider myself a newbie to vbscript. Been working with VBA for a bit
> however. I'm trying to see if I can interact with applications using event
> based code. An example of such is:
>
> 'Snip******************************
> Option Explicit
> Dim objExcel
> Dim i
> Set objExcel = CreateObject("Excel.Application")
> WScript.ConnectObject objExcel,"objExcel_"
> objExcel.Visible = True
> objExcel.Workbooks.Add
> i = 0
> Do
> WScript.Sleep(100)
> i = i + 1
> Loop While (i < 100)
> WScript.Echo("Script Complete")
>
> Sub objExcel_WindowActivate()
> WScript.Echo("WindowActivate")
> End Sub
> 'Snip******************************
>
> I tried referencing some of the articles in the library, but I think I wound
> up confusing myself. The above code just returns an error that it can not
> connect to the object. If I use WScript.CreateObject("Excel.Application",
> "objExcel_") instead, it compiles, but does not respond to events. Any
> pointers for a newbie?
>
> -J