Macro to execute on WEB Query Refresh

D

Donnie Stone

I have a macro I want to run after my WEB Query Refresh takes place. Any
assistance would greatly be appreciated.

Regards,

Donnie
 
H

Haldun Alay

Hi,

To execute some codes after Query refresh or before Query refresh;

1. add a class module to your VBA project. (assumed name is class1)
2. copy following line into your class module.

Public WithEvents qtQueryTable As QueryTable
Sub InitQueryEvent(QT As Object)
Set qtQueryTable = QT
End Sub

3. if you click Object Combobox to drop down, you'll see qtQueryTable on the
list. select it. there will be two events available for Query Table.
"AfterRefresh and BeforeRefresh". Write your code there.

4. before using these events, you need to set up your query table's
AfterRefresh and BeforeRefresh events using following code. (It could be in
worksheet's code or workbook's code)

Dim clsQueryTable As New Class1

Sub RunInitQTEvent(Optional FakeArg As Integer)
clsQueryTable.InitQueryEvent QT:=Sheet1.QueryTables(1) 'assumed
your query table in sheet1
End Sub

Private Sub Worksheet_Activate()
RunInitQTEvent
End Sub

'///// or /////
Dim clsQueryTable As New Class1

Sub RunInitQTEvent(Optional FakeArg As Integer)
clsQueryTable.InitQueryEvent QT:=Sheet1.QueryTables(1) 'assumed
your query table in sheet1
End Sub
Private Sub Workbook_Open()
RunInitQTEvent
End Sub


Good luck

Kind regards.


Haldun Alay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top