Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default I need help with QueryTable Events (AfterRefresh)

I have searched discussions groups and googled til I can't take it no more.
I have been trying to get the qtQueryTable_AfterRefresh with no success.
Here is my code....

ThisWorkbook contains the following:

Option Explicit
Dim QT As ClsModQT
Dim wsQuery As Worksheet
Private Sub Workbook_Open()

Set QT = New ClsModQT
Set wsQuery = Sheets("HD")
QT.InitQueryEvent wsQuery.QueryTables(1)

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.ThisWorkbook.RefreshAll
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Class Module ClsModQT contains the following....

Sub InitQueryEvent(QT As Object)
Set qtQueryTable = QT
End Sub

Private Sub Class_Initialize()

End Sub

Private Sub qtQueryTable_AfterRefresh(ByVal Success As Boolean)

Dim wsCurrent As Worksheet
Dim rngUsed As Range
Dim strFormula As String

' Refresh Age Column on HD Worksheet

Set wsCurrent = Application.Worksheets("HD")
Set rngUsed = GetUsedRange(wsCurrent)

For r = 2 To rngUsed.Rows.Count
strFormula = "=NOW()-G" & r
rngUsed.Cells(r, 8).FormulaR1C1 = strFormula
Next r

' Refresh Age Column on CHG Worksheet

Set wsCurrent = Application.Worksheets("CHG")
Set rngUsed = GetUsedRange(wsCurrent)

For r = 2 To rngUsed.Rows.Count
strFormula = "=NOW()-G" & r
rngUsed.Cells(r, 8).FormulaArray = strFormula
Next r

Set wsCurrent = Nothing
Set rngUsed = Nothing

End Sub

The afterrefresh never fires. What am I doing wrong?

Thank you in advance for any assistance.

Regards, Dean.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default I need help with QueryTable Events (AfterRefresh)

Hi Dean,

In your class module code you don't show the declaration for the
qtQueryTable variable. It should be in the general declaration section at
the top of the class module and look something like this:

Private WithEvents qtQueryTable As Excel.QueryTable

The key feature of the declaration being the inclusion and proper location
of the WithEvents keyword.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Dean Hinson" wrote in message
...
I have searched discussions groups and googled til I can't take it no more.
I have been trying to get the qtQueryTable_AfterRefresh with no success.
Here is my code....

ThisWorkbook contains the following:

Option Explicit
Dim QT As ClsModQT
Dim wsQuery As Worksheet
Private Sub Workbook_Open()

Set QT = New ClsModQT
Set wsQuery = Sheets("HD")
QT.InitQueryEvent wsQuery.QueryTables(1)

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.ThisWorkbook.RefreshAll
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Class Module ClsModQT contains the following....

Sub InitQueryEvent(QT As Object)
Set qtQueryTable = QT
End Sub

Private Sub Class_Initialize()

End Sub

Private Sub qtQueryTable_AfterRefresh(ByVal Success As Boolean)

Dim wsCurrent As Worksheet
Dim rngUsed As Range
Dim strFormula As String

' Refresh Age Column on HD Worksheet

Set wsCurrent = Application.Worksheets("HD")
Set rngUsed = GetUsedRange(wsCurrent)

For r = 2 To rngUsed.Rows.Count
strFormula = "=NOW()-G" & r
rngUsed.Cells(r, 8).FormulaR1C1 = strFormula
Next r

' Refresh Age Column on CHG Worksheet

Set wsCurrent = Application.Worksheets("CHG")
Set rngUsed = GetUsedRange(wsCurrent)

For r = 2 To rngUsed.Rows.Count
strFormula = "=NOW()-G" & r
rngUsed.Cells(r, 8).FormulaArray = strFormula
Next r

Set wsCurrent = Nothing
Set rngUsed = Nothing

End Sub

The afterrefresh never fires. What am I doing wrong?

Thank you in advance for any assistance.

Regards, Dean.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default I need help with QueryTable Events (AfterRefresh)

One important item you omitted: Where and how do you Dim your qtQueryTable
variable? It needs to be defined WithEvents in order to use the event
procedures - can't tell whether you did this or not.

"Dean Hinson" wrote:

I have searched discussions groups and googled til I can't take it no more.
I have been trying to get the qtQueryTable_AfterRefresh with no success.
Here is my code....

ThisWorkbook contains the following:

Option Explicit
Dim QT As ClsModQT
Dim wsQuery As Worksheet
Private Sub Workbook_Open()

Set QT = New ClsModQT
Set wsQuery = Sheets("HD")
QT.InitQueryEvent wsQuery.QueryTables(1)

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.ThisWorkbook.RefreshAll
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Class Module ClsModQT contains the following....

Sub InitQueryEvent(QT As Object)
Set qtQueryTable = QT
End Sub

Private Sub Class_Initialize()

End Sub

Private Sub qtQueryTable_AfterRefresh(ByVal Success As Boolean)

Dim wsCurrent As Worksheet
Dim rngUsed As Range
Dim strFormula As String

' Refresh Age Column on HD Worksheet

Set wsCurrent = Application.Worksheets("HD")
Set rngUsed = GetUsedRange(wsCurrent)

For r = 2 To rngUsed.Rows.Count
strFormula = "=NOW()-G" & r
rngUsed.Cells(r, 8).FormulaR1C1 = strFormula
Next r

' Refresh Age Column on CHG Worksheet

Set wsCurrent = Application.Worksheets("CHG")
Set rngUsed = GetUsedRange(wsCurrent)

For r = 2 To rngUsed.Rows.Count
strFormula = "=NOW()-G" & r
rngUsed.Cells(r, 8).FormulaArray = strFormula
Next r

Set wsCurrent = Nothing
Set rngUsed = Nothing

End Sub

The afterrefresh never fires. What am I doing wrong?

Thank you in advance for any assistance.

Regards, Dean.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ODBC AfterRefresh Event and Shared Workbook Paul Excel Worksheet Functions 0 January 8th 08 05:34 PM
Add QueryTable in code Jim Hughes Excel Programming 4 March 13th 05 08:28 AM
Can't change name of querytable. Bing Excel Programming 0 March 12th 05 05:57 PM
Querytable Ben.c Excel Programming 4 December 3rd 03 09:11 AM
MS QUERY w/out querytable No Name Excel Programming 1 October 24th 03 03:55 PM


All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"