+ Reply to Thread
Results 1 to 8 of 8

Workbook.Close causes 2010 to dump

  1. #1
    Registered User
    Join Date
    05-09-2005
    Posts
    10

    Angry Workbook.Close causes 2010 to dump

    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?

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Workbook.Close causes 2010 to dump

    Read question #4 on
    http://www.excelitems.com/2010/12/ex...questions.html

    I wonder if there is a problem with where the code is and what workbook is closing. I suggest this only because it works in debug mode and ThisWorkbook would be open then.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    05-09-2005
    Posts
    10

    Re: Workbook.Close causes 2010 to dump

    I agree entirely but surely you should be able to close the active workbook without Excel dumping? After all it works perfectly well on 97, 2000 and 2003. Any ideas how I could close it? Someone suggested creating the new book in a new instance of Excel but the code would still be executing in the original one and cause the problem?

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Workbook.Close causes 2010 to dump

    I love your statement of:
    After all it works perfectly well on 97, 2000 and 2003.
    Micorsoft did a lot of changes between 2003 and 2007 versions. Most of them were "improvements".

    You are saying that it doens't work on 2007 but did work on 2003 and that is the only difference.(?) Things changed! Now how do you fix it so it works on 2007??

    I'm asking if you closed the workbook that had the code in it. I'm not sure you answered that question.

  5. #5
    Registered User
    Join Date
    05-09-2005
    Posts
    10

    Re: Workbook.Close causes 2010 to dump

    Yep, I close the workbook that has the code in it. The Close is the very last statement.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Workbook.Close causes 2010 to dump

    Have you tried a line of:
    Please Login or Register  to view this content.
    http://msdn.microsoft.com/en-us/library/bb177478.aspx

  7. #7
    Registered User
    Join Date
    05-09-2005
    Posts
    10

    Re: Workbook.Close causes 2010 to dump

    Yes. I haven't put the full code in the post but I have all that stuff in and even tried to trap the error but this isn't an alert or a normal VB error. It is a crash in the Excel application that causes everything in that instance to be closed down. I think MS in their wisdom have "fixed a bug" that allowed you to still run VB code even after you had closed the book because it still kept the VB instance running. Anyway, it looks like a work around is in order just like most MS "features". I will let you know if I find a good one.

  8. #8
    Registered User
    Join Date
    05-09-2005
    Posts
    10

    Thumbs up Re: Workbook.Close causes 2010 to dump

    Ok! I've had to give in on this one and simply do a workaround. Instead of simply closing the book that ran the code and leaving the newly created book as the only one active, I set the code book as read_only and protect it. At the end of the code I simply activate the new book and hide the code book. Then when the user closes excel it disappears. I don't have anyone out there capable of making it visible and then saving their own copy so they can hack it but even if there was I have protected the code as well so they will have to be pretty determined to get into it. It's not ideal but as far as the users are concerned it looks the same and works the same. For anyone out there who is interested it seems like the problem is in 2010 and only when external data is involved. I have created books that simply create other books, do a bit of cell population then close and that works fine. However, if I change the the code to populate the cells via a DB connection when it hits the close it crashes saying it "has encountered a problem and must close"!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1