Hello all,
I'll do my best to explain my problem, as it involves couple of parallel aspects.
The BIG PICTURE:
I've been working in a file with multiple sheets, multiple pivot tables and few queries.
As the excel sheet is a database with more than 30 different sheets and components, I've been hiding and un-hiding the tabs as the user clicks the DB which he wants to access. Ok. This is done and it works fine.
All pivot tables were updated automatically using the RefreshALL function...
The PROBLEM:
I've started to face problems when I started trying to update individual queries as the RefreshAll takes too long for the quantity of tables and queries I have.
When I click a button I'd like to go to another worksheet and as soon as the worksheet is deactivated I'd like to update the query.
I've been using the following code for refresh the query:
The refresh is partially succesfull. However, the program is not going to the sheet I'd like to activate, it goes to the "MAIN MENU" instead...
Any idea how could I ensure to update the queries, unhide and go to the desired sheet?? Below the code
P.S.: This happens only when I try to refresh the QUERIES, i have disabled then and the PIVOT tables would update fine and go to the proper worksheet.
Thanks a lot!
I'll do my best to explain my problem, as it involves couple of parallel aspects.
The BIG PICTURE:
I've been working in a file with multiple sheets, multiple pivot tables and few queries.
As the excel sheet is a database with more than 30 different sheets and components, I've been hiding and un-hiding the tabs as the user clicks the DB which he wants to access. Ok. This is done and it works fine.
All pivot tables were updated automatically using the RefreshALL function...
The PROBLEM:
I've started to face problems when I started trying to update individual queries as the RefreshAll takes too long for the quantity of tables and queries I have.
When I click a button I'd like to go to another worksheet and as soon as the worksheet is deactivated I'd like to update the query.
I've been using the following code for refresh the query:
VBA Code:
ActiveWorkbook.Connections("Query - Name").Refresh
The refresh is partially succesfull. However, the program is not going to the sheet I'd like to activate, it goes to the "MAIN MENU" instead...
Any idea how could I ensure to update the queries, unhide and go to the desired sheet?? Below the code
VBA Code:
Private Sub Button_Click()
Sheets("1").Visible = True
ThisWorkbook.Sheets("1").Activate
End Sub
Private Sub Worksheet_Deactivate()
ActiveWorkbook.Connections("Query - X").Refresh
ThisWorkbook.Sheets("1").Visible = False
End Sub
P.S.: This happens only when I try to refresh the QUERIES, i have disabled then and the PIVOT tables would update fine and go to the proper worksheet.
Thanks a lot!