Taras
asked on
Pivot table Refresh on File Open
I am using Excel 2007. I have a Pivot Table that is getting External data from SQL Server via Microsoft Query. This uses a named connection and that connection has properties, including a Command Text Property. This contains the query string that pulling data in In my workbook on sheet1 which I named All_Data.
I have my pivot table on Sheet2 which I named Pivot. Source for my pivot table is Sheet1 – All_data and used dynamic range which I named Pivot_Range.
Pivot_Rage=All_Data!$A$1:I NDEX(All_D ata!$1:$10 48576,MATC H("ZZZZZZ" ,All_Data! $A:$A), MATCH("ZZZZZZ",All_Data!$1 :$1))
What I need is how to refresh my workbook on file open. I assume that when Sheet1- All_Data is refreshed that my pivot table on Sheet2- Pivot will be refreshed automatically.
I got some suggestion from
Calacuccia:
Private Sub Workbook_Open()
Me.Worksheets("Sheet1").Pi votTables( 1).PivotCa che.Refres h
End Sub
and MelindaJonson
Right click on pivot table
click PivotTable options
click on the Data tab
check the box "Refresh data when opening file"
However they not working.
I tried this too:
Me.Worksheets("All_Data"). QueryTable s(1).Refre sh
Me.Worksheets("Pivot").Piv otTables(1 ).RefreshT able
And on first line I got Run time error ‘9’ Subscript Out of range.
How to got this working in this scenario.
And how to get this working in scenario when I have just one spreadsheet, that have just pivot table on in my case worksheet “Pivot” with out having worksheet All_Data which I use as source for my pivot table.
I have my pivot table on Sheet2 which I named Pivot. Source for my pivot table is Sheet1 – All_data and used dynamic range which I named Pivot_Range.
Pivot_Rage=All_Data!$A$1:I
What I need is how to refresh my workbook on file open. I assume that when Sheet1- All_Data is refreshed that my pivot table on Sheet2- Pivot will be refreshed automatically.
I got some suggestion from
Calacuccia:
Private Sub Workbook_Open()
Me.Worksheets("Sheet1").Pi
End Sub
and MelindaJonson
Right click on pivot table
click PivotTable options
click on the Data tab
check the box "Refresh data when opening file"
However they not working.
I tried this too:
Me.Worksheets("All_Data").
Me.Worksheets("Pivot").Piv
And on first line I got Run time error ‘9’ Subscript Out of range.
How to got this working in this scenario.
And how to get this working in scenario when I have just one spreadsheet, that have just pivot table on in my case worksheet “Pivot” with out having worksheet All_Data which I use as source for my pivot table.
Subscript out of range is often because your Worksheet name is not correct.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>Subscript out of range is often because your Worksheet name is not correct.That was my first thought as well, but in this case it looks like a quirk of how ListObjects that are linked to external data sources behave :)
ASKER
Calacuccia you or me missing something here, probably me.
Yes I gave exact name:
Me.Worksheets("Pivot").Piv otTables(1 ).PivotCac he.Refresh
It runs without error and it did what is saying to do. It refreshed pivot table with data that are not refreshed means old data (from source that is not refreshed).
Source of pivot table is All_data Sheet1 and that Sheet1 is getting data from SQL Server query as I explained. Source of pivot table is not refreshed. Pivot table is just refreshed with old data from Sheet1-All_Data.
Yes I gave exact name:
Me.Worksheets("Pivot").Piv
It runs without error and it did what is saying to do. It refreshed pivot table with data that are not refreshed means old data (from source that is not refreshed).
Source of pivot table is All_data Sheet1 and that Sheet1 is getting data from SQL Server query as I explained. Source of pivot table is not refreshed. Pivot table is just refreshed with old data from Sheet1-All_Data.
Ok, I am missing something, I believe Patrick is on the right track.
ASKER
Patrick example is very good, however I can use It when I got data from SQL Server in my Workbook.
To adjust my question and address problem properly, I need to ask question like this.
How I can refresh my data in Sheet1 – All_Data on open file with upper mentioned scenario. Forget pivot table.
To adjust my question and address problem properly, I need to ask question like this.
How I can refresh my data in Sheet1 – All_Data on open file with upper mentioned scenario. Forget pivot table.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Patrick it is not working.
Simply , I need something that will do the same thing like :Go to data tab in excel menu and press Refress All .
After I press Refress All (ctr+Alt+F5) it refreshed properly.
Simply , I need something that will do the same thing like :Go to data tab in excel menu and press Refress All .
After I press Refress All (ctr+Alt+F5) it refreshed properly.
ASKER
I found it and it is working.
Private Sub Workbook_Open()
ActiveWorkbook.RefreshAll
End Sub.
Private Sub Workbook_Open()
ActiveWorkbook.RefreshAll
End Sub.
Nice & simple
>>Patrick it is not working.Please explain what you mean by that, because it worked perfectly for me.
ASKER
Thanks a lot
Have you tried this exact command with "Sheet2"? (of course you have to give the exact name which you used for sheet2 (as your pivottable is in Sheet2)..