>>
APLDN Home

>>
Events

>>
Trainings

>>
APL Books

>>
APLDN Links

>>
Discussion Groups

>>
Downloads

>>
Articles

>>
Library

>>
Learning Tools

>>
APLDN User IO

>>
APL2000.com




General

Author Thread: Excel events in APL
Nancy.Griggs
Excel events in APL
Posted: Wednesday, January 17, 2007 4:53 PM (EST)
Believe it or not, I've just started working with Excel as an ActiveX object in APL.  I'm having trouble getting APL to "see" the events that occur in Excel.  I'm sure this is old news, but I can't find anything in my APL resources that discuss it.  Can anyone point me in the right direction?  Thanks, Nancy


Comments:

Author Thread:
davin.church
Excel events in APL
Posted: Wednesday, January 17, 2007 5:34 PM (EST)

I haven't tried capturing them, but there seem to be normal events available for use.  I assume you've tried those?

     

Michael.Shumate
Excel events in APL
Posted: Wednesday, January 17, 2007 5:59 PM (EST)

If you look at 'obj' []wi 'events' you should see the events to which a handler could be attached.

 

/mas

     

Nancy.Griggs
Excel events in APL
Posted: Wednesday, January 17, 2007 6:31 PM (EST)

I did what I considered the normal stuff:  linked to Excel, created a workbook , and loaded an XML file.  I first tried adding onClose event handlers because (among other things) I want APL to "know" if the user closes the spreadsheet and/or Excel.  But, when I close them manually, nothing happens in APL.  I found the following on the MSDN website, but I don't know anything about Visual Basic, so I'm having a hard time making the conversion.  Thanks for your help!  Nancy

 

Office Excel 2003 VBA Language Reference
Using Events with the Application Object [Excel 2003 VBA Language Reference]
Before you can use events with the Application object, you must create a new class module and declare an object of type Application with events. For example, assume that a new class module is created and called EventClassModule. The new class module contains the following code.

 

Public WithEvents App As Application
  
After the new object has been declared with events, it appears in the Object drop-down list box in the class module, and you can write event procedures for the new object. (When you select the new object in the Object box, the valid events for that object are listed in the Procedure drop-down list box.)

Before the procedures will run, however, you must connect the declared object in the class module with the Application object. You can do this with the following code from any module.

 

Dim X As New EventClassModule

Sub InitializeApp()
    Set X.App = Application
End Sub
  
After you run the InitializeApp procedure, the App object in the class module points to the Microsoft Excel Application object, and the event procedures in the class module will run when the events occur.

     

Mike.Gecko
Excel events in APL
Posted: Thursday, January 18, 2007 3:05 AM (EST)

Hello Nancy,

You need to keep in mind which object's events you want to interact with.  Possibilities are the application object, the workbook, the worksheet, a range, etc.

 

I've attached a ws in the downloads area showing how to do it. [There doesn't seem to be a facility to attach files here.] 

 

I hope this helps you in the right direction.

 

Mike

     

Nancy.Griggs
Excel events in APL
Posted: Friday, January 19, 2007 1:25 PM (EST)

Hi Mike,

Thanks for the ws!  Seeing how you did things is a big help. 

 

I am still having a problem, though.  e.g., in your <TEST_EXCEL_> put a stop on line 86.  Run it to the stop, and then go over to Excel and manually change the contents of cell B6 from  "23" to "CD".  No events are triggered in APL even though an onXChange handler is set for the worksheet on lines 57-59. Also, nothing happens in APL when I manually close the workbook even though onXBeforeClose is set on lines 47-49. 

 

Can APL only see events in a linked Excel session that are triggered programmatically but not manually?

 

Thanks for everything!

Nancy

 

     

Mike.Gecko
Excel events in APL
Posted: Friday, January 19, 2007 5:21 PM (EST)

Hello Nancy,

 

You are right.  I've experimented a bit more and it seems that things do not work as expected in response to user interaction.  The documentation seems to conceed this.  The documentation for the "modifed" property (which I assumed would be affected) says:

"This property is present on ActiveX objects, but they are not closely enough connected to the APL+Win system to recognize the parentage-chain modified relationships; for the nonce, this functionality is not available."

 

Sorry, that puts it beyond what I can help you with.  Prior to your question I had not tried to interact with the events from Excel, but I've made extensive use of the methods and properties , in case you need help with that.

 

Regards,

Mike

 

 

     

Nancy.Griggs
Excel events in APL
Posted: Friday, January 19, 2007 9:34 PM (EST)

Hi Mike,

 

Yes, I had given up hoping that the handlers for regular APL events, like onModified, would work.  But, I thought surely the X event handlers, like onXChange, should work.  According to the Excel documentation, it is supposed to fire for any change to a sheet.  So, why can't we see it?  I really hope this is not a limitation of APL.

 

Thanks again, and have a great weekend!

Nancy

     

Support
Excel events in APL
Posted: Friday, January 19, 2007 10:49 PM (EST)

Nancy,

It is the stop on line 86 that is responsible for the onXChange and the rest of the handlers not firing in APL.  Why you ask?  Because the stop causes the function to suspend and event handlers (callbacks) do not fire in APL during a suspension.  This is corroborated by the message, "(Callbacks ignored while suspended)", that is displayed in the status bar during a suspension in APL.  Replacing the stop with a comment will enable the handlers to continue firing.

APL2000 Support

     

Nancy.Griggs
Excel events in APL
Posted: Monday, January 22, 2007 10:27 AM (EST)

Woo Hoo!!  Success!

Thanks to all of you.  You are such a blessing.

Nancy

     



APL2000 Official Web Site

May the smile on your face Come straight from your heart
--- Anonymous

APLDN Home   |    |  Events   |  Trainings   |  APL Books   |  APLDN Links   |    |  Discussion Groups   |    |  Downloads   |  Articles   |  Library   |  Learning Tools   |  APLDN User IO   |  APL2000.com   |