Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Convert hard coded query criteria to Parameter Query | Excel Discussion (Misc queries) | |||
Excel 2007 / MS Query - editing existing query to another sheet | Excel Discussion (Misc queries) | |||
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? | Excel Discussion (Misc queries) | |||
How to make first Row inert? | Excel Discussion (Misc queries) | |||
How to use a Access Query that as a parameter into Excel database query | Excel Discussion (Misc queries) |