I have a read_only workbook that creates another workbook then populates it with a pivot table. After successfully creating the pivot workbook it closes itself so the new workbook is the only one left. This has been working for my users on Excel 2000 and 2003 with no problem. We are now moving from 2003 to 2010 and when Excel encounters the .Close for the book it closes the book, the pivot table and chart are clearly displayed and then within less than a second we get ... Excel has encountered a problem and needs to close.
Here is the main thrust of the code:
In the read_only book I have .....
Dim Reportwb As Workbook
Dim Pivotwb As Workbook
...... initialize some variables then ...
Set Reportwb = ActiveWorkbook
Workbooks.Add
Set Pivotwb = ActiveWorkbook
...... set up connection strings etc. then ...
With Pivotwb.PivotCaches.Add(SourceType:=xlExternal)
...... Format the Pivot table fields then ...
Charts.Add
...... Format the chart type etc. then ...
ActiveChart.Deselect
Reportwb.Close SaveChanges:=False
When it encounters the last statement it gives the error. If I comment out the line it works fine. I have tried all different ways to close the book, even trying to close the window but no matter what I do it causes the error. However, if I run it in debug it executes OK! In addition I have tried running it in compatibility mode but it still dumps out! Anybody got any ideas?
Bookmarks