Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Workbook.close still leaving VBA Project open???

Status
Not open for further replies.

innov

Programmer
May 20, 2004
40
US
Hello all.

I've just added some code to check for an environment supported by my Excel VBA app. At this time, is only Excel XP (version 10). If the version is NOT supported (i.e. Excel 2K), the workbook is closed without saving. Problem is, the VBA Project is still hanging around!!

I've verifed in the task manager that the Excel wkbk is gone. And not only that, but when I re-open wkbk, there now 2 of the same VBA Projects.

Below is the code in the Workbook_Open event. The Environ_OK is just a function that returns a boolean based on the Excel vesion.

Thanks for your help!

Innov

P.S. Is there a way to do this BEFORE all of the links a established, etc.


Code:
Private Sub Workbook_Open()
  Application.EnableCancelKey = xlDisabled
  If trap_errors Then: On Error GoTo Err_Handler
  error_source = "Workbook_Open"
  initial_open = True
  
  Application.Calculation = False
  Application.EnableEvents = False
  
  If Not Environ_OK Then   
    Application.DisplayAlerts = False
    ThisWorkbook.Close (False)  'don't save changes since version not supported
    Exit Sub
  End If

 
Is the code behind the workbook you are closing or a different one?

Have you considered closing Excel entirely

Application.Quit
 
If I understand your question, yes the code's behind the workbook I'm closing (hence ThisWorkbook.close).

Since I don't start a separate instance of excel for my app, I'd rather not kill other workbooks that the user may have open.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top