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

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

tmassoglia01Asked:
Who is Participating?
 
Rory ArchibaldConnect With a Mentor Commented:
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
 
tmassoglia01Author Commented:
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
 
Rory ArchibaldCommented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
tmassoglia01Author Commented:
They are all pointing to the same cube but using different selection queries.
0
 
tmassoglia01Author Commented:
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
 
Rory ArchibaldCommented:
I am confused - did you solve this? (I had some actual work to do, so got called away)
Rory
0
 
tmassoglia01Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.