IUIAutomationStructureChangedEventHandler Interface RRS feed

  • Question

  • Hi,

    I am using VBA in Excel and UIAutomationClient. Specifically, I wonder whether anyone could help me understand why I cannot get IUIAutomationStructureChangedEventHandler to work? I have been able to successfully implement IUIAutomationFocusChangedEventHandler and other event handlers. What I have done there is create a new class module containing the event handler and then used the 'new' keyword to create it in my main code and add it to the IUIAutomationElement on which I want to listen. Whereas with the IUIAutomationFocusChangedEventHandler, once I have established it in the class module with the 'implements' keyword, the drop down menus pull in a "template" method to which I can add what I want the event handler to do, this does not happen for IUIAutomationStructureChangedEventHandler. 

    Presently, when I use the new keyword with the class module containing the IUIAutomationStructureChangedEventHandler, Excel crashes.

    Any advice would be much appreciated.

    Wednesday, August 12, 2020 8:26 PM

All replies

  • The documented handler functions of these interfaces have different number of parameters. Show some details about your code.

    Thursday, August 13, 2020 7:25 AM
  • Hi Viorel,


    Option Explicit

    Implements IUIAutomationStructureChangedEventHandler

    Sub IUIAutomationStructureChangedEventHandler_HandleStructureChangedEvent (sender As IUIAutomationElement, changeType as StructureChangeType, runtimeID As Long)

    MsgBox "Success"

    End Sub

    If you look at IUIAutomationStructureChangedEventHandler in the Object Browser, this appears to be in order.

    In my main code:

    Option Explicit
    Dim EH As IUIAutomationStructureChangedEventHandler
    Set EH = New Class1

    Excel Crashes

    Saturday, August 15, 2020 11:57 AM
  • Does it crash immediately or after displaying some message?

    Perform an experiment: change the parameters to ‘ByRef sender As IUIAutomationElement, ByVal changeType as StructureChangeType, ByVal runtimeID As LongPtr’.

    • Edited by Viorel_MVP Saturday, August 15, 2020 1:29 PM
    Saturday, August 15, 2020 1:25 PM
  • It crashes immediately. Have tried the experiment, but no luck unfortunately.
    Sunday, August 16, 2020 3:38 PM
  • Hi Viorel,

    Sorry to be a pest. Wondering whether you have any ideas? Were you able to replicate the problem?

    Wednesday, August 19, 2020 6:56 PM
  • Yes, the problem is reproduced, but no solution found.

    Wednesday, August 19, 2020 6:59 PM
  • Thanks for coming back to me. Appreciate it.
    Wednesday, August 19, 2020 8:25 PM