Results 1 to 5 of 5

Thread: Getting the events of other workbooks

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    27

    Getting the events of other workbooks

    How do I refer to an event and create a function for the event of another workbook?

    I have a AddInWorkbook.xla that works as a add in and it needs to refer to whatever new workbook that the user opens. I need the new workbook to tell the AddInWorkbook.xla when the new workbook's closing event is dispatched.

    So it is possible to do something like this in VBA Excel?

    Or otherwise like adding a event listener to it? Possible?
    PHP Code:
    //inside AddInWorkbook.xla
    ActiveWorkbook.addEventListener("Workbook_Close"closeHandler)
    function 
    closeHandler(Event e) {
       if 
    e.filename == ActiveWorkbook.filename {
          
    //then from here I can carry on...
       
    }


  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Getting the events of other workbooks

    create a class and declare it with events
    set the class to the excel application
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    27

    Re: Getting the events of other workbooks

    Thanks.
    But how do I declare the events and set the class to the application? Are there any examples? Sorry as this is the first time I am doing this.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Getting the events of other workbooks

    check in the help file
    using events with application object
    or
    application object events

    if you get stuck i can try to help, but it is not real hard once you start
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    27

    Re: Getting the events of other workbooks

    Thanks westconn. I found the page in the help file. I will try and let u know the result. Thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width