ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   MS Query becomes inert (https://www.excelbanter.com/excel-programming/422246-ms-query-becomes-inert.html)

Jonathan Cooper

MS Query becomes inert
 
Excel 2003, Windows XP

I have a query embedded in a worksheet. If I select a cell within the
query, I am able to refresh the data without any problems. However, normally
I use the following macro to refresh the queries in the workbook, since other
non-technical users also use this file. Most of the time, this works without
any problems.

Sub Auto_Open()

Dim ws As Worksheet
Dim qt As QueryTable
Dim pt As PivotTable
Dim Answer As Variant
Dim RunMe As Variant

'Double check that the user wants to retrieve new data from Movex.
RunMe = MsgBox("Do you want to get updated data from Movex", vbYesNo +
vbQuestion, "Movex Update")
If RunMe = vbNo Then Exit Sub


'Turn off screen updating and calculation to save time
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'Cycle through all worksheets and refresh all querytables
For Each ws In ThisWorkbook.Worksheets
For Each qt In ws.QueryTables
qt.Refresh False
Next qt
Next ws

'after downloads complete, recalculate all formulas copied by the MS query
download
Application.CalculateFull

'Cycle through and refresh all pivot tables
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next pt
Next ws

'Set calculation back to automatic
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

'Notify that everything is finished
Answer = MsgBox("Download complete", vbOKOnly, "Movex ODBC Download")

End Sub

However, sometimes the macro fails at the statement 'qt.Refresh False'
After this happens, I go back and find that the query is no longer a query.
I know this because the External Data Toolbar buttons become grayed out. If
I go into INSERT-NAMES-DEFINE, I can see that the query name now has spaces
in it.

Before running the macro, it looks like this =Sheet1!$A$1:$E$415
When the macro fails, if I go back in it will look like = Sheet1!$A$1:$E$415
(notice the spaces after the equal sign)

Does anyone have any guesses what the problem is?



All times are GMT +1. The time now is 01:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com