Test to see how many worksheets are open and closing active worksheet

S

Steve Lowe

Hi

I'm using the Application.Quit command in a macro assigned to a button
on a worksheet.

However if I have other spreadsheets open as well as the one that has
this macro in it they too are closed.

How do I test to see if other worksheets are open ?

How do I close just the active worksheet ?

Sorry for the very basic questions.

Thanks



Steve Lowe.
- Steve Lowe
- E-Mail : (e-mail address removed)
- Before Replying Remove .NO.SPAM
- UK Resident although my e-mail address is usa.net
 
C

Chip Pearson

Steve,

You can determine how many workbooks are open with
Workbooks.Count. Note that this includes hidden workbooks (e.g.,
your personal.xls file) but not add-ins. You can close the active
workbook with code like

ActiveWorkbook.Close SaveChanges:=True ' or False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
S

Steve Lowe

Hi Chip

Thanks - got it working just right

Regards,

Steve.




Steve,

You can determine how many workbooks are open with
Workbooks.Count. Note that this includes hidden workbooks (e.g.,
your personal.xls file) but not add-ins. You can close the active
workbook with code like

ActiveWorkbook.Close SaveChanges:=True ' or False

- Steve Lowe
- E-Mail : (e-mail address removed)
- Before Replying Remove .NO.SPAM
- UK Resident although my e-mail address is usa.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top