XL2002: Worksheet Change Causes Query Table to Be Refreshed Repeatedly (287103)
The information in this article applies to:
This article was previously published under Q287103 SYMPTOMS
If you change any cell or refresh a query table in a Microsoft Excel workbook, Excel may repeatedly refresh any query tables in the workbook without stopping.
CAUSE
This behavior can occur if you have a Microsoft Visual Basic for Applications (VBA) macro that refreshes query tables when a Change event occurs. Refreshing the query table triggers another Change event, which causes the macro to start again. The following sample macro causes this behavior to occur:
Private Sub WorkSheet_Change(ByVal Target as Range)
ThisWorkbook.Worksheets(1).Range("A2").QueryTable.Refresh BackgroundQuery:=False
End Sub
This sample macro refreshes the query table that intersects cell A2 on Sheet1 when a change is made to the worksheet.
RESOLUTION
To stop the repeated refreshing of the query table, press the ESC key.
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either
expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals can
help explain the functionality of a particular procedure, but they will not
modify these examples to provide added functionality or construct procedures to
meet your specific needs. If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or the Microsoft fee-based
consulting line at (800) 936-5200. For more information about Microsoft Certified
Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
To work around this issue, change your macro code so that query tables are not refreshed because of a change event. When you refresh a query table in earlier versions of Excel, this does not trigger Change events. The following code illustrates how the earlier sample macro should be changed to run correctly in all versions of Excel:
Private Sub WorkSheet_Change(ByVal Target as Range)
If Val(Application.Version) < 10 Then
'Check the version of Excel.
ThisWorkbook.Worksheets(1).Range("A2").QueryTable.Refresh BackgroundQuery:=False
End If
End Sub
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCESFor more information about worksheet change events, click Microsoft Visual Basic Help on the Help menu, type sheetchange event in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbbug kbpending KB287103 |
---|
|