Workbook problem

  • Thread starter Thread starter Guest
  • Start date Start date
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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,223,406
Messages
6,171,926
Members
452,434
Latest member
NUC_N_FUTS2

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