VBA For Excel AfterRefresh Event

后端 未结 3 1889
太阳男子
太阳男子 2021-01-14 08:19

I am using the following QueryTable Inquiry. After the .Refresh executes the VBA procedure ends. The inquiry works but I need to execute code after it complete

3条回答
  •  鱼传尺愫
    2021-01-14 08:49

    A github repo that demonstrates the minimum code needed to get this working can be found here.

    As mentioned in the other answers, the key factors to ensuring you catch the event are:

    1. Declare a global variable of your event-handling class module's type outside of any subroutines/methods, at the top of a file (I chose the ThisWorkbook file).

    2. Add a Workbook_Open event handler and instantiate that variable there, so that it is available immediately and will remain in scope (since it's global).

    3. At that point, or at any downstream point when you have a QueryTable you're interested in, pass that QueryTable to the global instance to wire up its events.

    (It took me a couple tries to figure this out myself, when someone pointed me in this direction as an answer to this question.)

提交回复
热议问题