Close a workbook while procedure is running

ajetrumpet

Banned for being rude
Joined
Apr 12, 2008
Messages
569
Office Version
  1. 365
  2. 2016
  3. 2007
Platform
  1. Windows
Hello all,

I have 2 workbooks on a CD, and what I want to do is this:


If the user opens the 97-2003 workbook with their version of 2007 Excel, I want to automatically close that book and open the correct workbook that is stored on the CD. I know how to check the drive for whatever it is set to as their CD drive, but what I don't know how to do is close a workbook as a procedure is being used in the process. Ideas please anyone?

(The procedure is being used in the 97-2003 version with the WORKBOOK_OPEN event, so it's even in the process of opening too!)


I have tried application.quit, and workbooks("workbook name").close, and both of these are not recognized. The procedure just runs through and ends accordingly.


Here is the code I am currently experimenting with:
Rich (BB code):
Private Sub workbook_open()

If Application.Version > 11 Then
  MsgBox "The correct version will now open."
    Workbooks.Open "ADDRESS OF CORRECT FILE"
      I WANT TO CLOSE THIS WORKBOOK RIGHT HERE (set focus to the other one)
        Exit Sub

Else
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Have you tried

Code:
ThisWorkbook.Close False

Not sure if the opening macro will cause problems with it tho
 
Upvote 0
I have figured this out. Thread closed, and thank you. I simply used a procedure that was located in another workbook that was being opened, and exited the subroutine that I was trying to use.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top