Workbook problem

G

Guest

Guest
Hello.

I have a situation

I have a Macro that loads a form where the user can choose what type of data he wants to load, the just has to click on the appropriate button and the data will be loaded.

One of the buttons is labelled 'Exit' and what this does is close Excel altogehter.

I use Application.Quit as the command

A colleague put a case forward that if the User has the Makro open and he decides to open a standard excel file, and then he chooses to exit the Makro, then both files will close because of the command Application.Quit

I would like the program to run so that when the Makro is loaded without any additional Excel files being opened and the user clicks on 'Exit' that Excel will close. But if an additional file is already open and the user loads the Makro and then decides to 'Exit' is it possible to check wether there are any Workbooks other than the Makro workbook present ?if so then only do an Activewindow.Close, if not then use the Application.Quit

Does anybody know how to put that into code?

I would be grateful for any help you can give.

Thanks.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
How about this?

Code:
If Excel.Workbooks.Count > 1 Then 'More than one workbook open
    ThisWorkbook.Close
Else
    Application.Quit
End If

HTH,
D
This message was edited by dk on 2002-03-07 09:40
 
Upvote 0

Forum statistics

Threads
1,213,492
Messages
6,113,967
Members
448,537
Latest member
Et_Cetera

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