Solved

Pivot Table Update Error: The cube file cannot be opened for writing.

Posted on 2007-03-21
7
1,369 Views
Last Modified: 2008-01-09
I am trying to programmatically update multiple pivot tables in an Excel spreadsheet.  These pivot tables all point to the same Access database.  I can update the first one fine, but when I try to update any of the other pivot tables I get the following error: "The cube file C:\Sales Budget 2007\Sales Budget Cube Detail.cub cannot be opened for writing.".  I also get this same error when trying to manually update each of the pivot tables.  If I save it, close Excel, then re-open I am able to update the next pivot table.  I am curently using this code to auto-update the pivot tables:
____________________________________________________________________________________
Sub Refresh_All_PTs()
On Error Resume Next
Application.EnableEvents = False
Dim ws As Worksheet
Dim Pt As PivotTable
If MsgBox("Do you wish to update ALL PivotTables in this workbook?", _
vbYesNo + vbQuestion + vbDefaultButton2, "Refresh PivotTables?") = vbNo Then Exit Sub
Application.StatusBar = "Updating PivotTables in current workbook!"
For Each ws In ActiveWorkbook.Worksheets
For Each Pt In ws.PivotTables
Pt.PivotCache.Refresh
If Err.Number <> 0 Then
MsgBox Err.Description
Err.Number = 0
End If
Next
Next
Application.StatusBar = False
Application.EnableEvents = True

End Sub
____________________________________________________________________________________

Any help in getting this to work would be appreciated.

Thanks,
Tony

0
Comment
Question by:tmassoglia01
  • 4
  • 3
7 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 18764246
If they all point to the same cube file, you should only need to update the pivotcache once, then issue a RefreshTable command on each pivottable.
HTH
Rory
0
 

Author Comment

by:tmassoglia01
ID: 18764332
Rory,

I modified my code to run Pt.PivotCache.Refresh once on the first pivot table, then run Pt.RefreshTable for each subsequent table, but I am still getting the cannot be opened for writing error.  I have pased my code below, am I not using the right statement?

______________________________________________________
For Each ws In ActiveWorkbook.Worksheets
For Each Pt In ws.PivotTables
If index = 0 Then
    Pt.PivotCache.Refresh
    index = 1
End If
Pt.RefreshTable
If Err.Number <> 0 Then
MsgBox Err.Description
Err.Number = 0
End If
Next
Next
______________________________________________________
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 18764521
Are all your pivottables based on the same cache (i.e. did you select the option to use the same data when you created each one)? Or are they all pointing at the same cube but using different data?
Regards,
Rory
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:tmassoglia01
ID: 18764563
They are all pointing to the same cube but using different selection queries.
0
 

Author Comment

by:tmassoglia01
ID: 18764839
As it stands right now, I will be updating my source Access database from a VB application, if I need to open and close the Excel workbook that would not be too big of an issue.  I would just need to be able to update the pivot table from my VB app.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 18766520
I am confused - did you solve this? (I had some actual work to do, so got called away)
Rory
0
 

Author Comment

by:tmassoglia01
ID: 18766886
Yes I was able to solve it.  With Excel 2007 I was able to give each pivot table a different cub file (all though I think I could have done it programmitically with Excel 2003 also).  Having each pivot table have it's own cub file makes me able to update each of the pivot tables without having to close and open Excel.  I don't know why I hadn't thought of doing that before, but your post got me thinking in that direction.  Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now