ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro closes excel and therefore won't run anymore (https://www.excelbanter.com/excel-programming/284460-macro-closes-excel-therefore-wont-run-anymore.html)

David_Stickland

Macro closes excel and therefore won't run anymore
 

Firstly, I am a very new macro writer so please be patient!

I have written a very simple macro to save the current work sheet an
then quit excel if no other files are open:

Sub saveandquit()

ActiveWorkbook.Save
ActiveWorkbook.Close

If IsEmpty(ActiveWorkbook) = True Then
Application.Quit
Else
Application.WindowState = xlMinimized
End If

End Sub

The problem being that I can't (i.e. don't want to) store the macro i
my personal.xls file. If the macro is saved in the worksheet when th
macro shuts the worksheet, it effectively shuts itself and therefor
doesn't run the rest of the code.

Can I save the macro separately and then call it from a specifie
location or is there a better way to do what I am trying to do?

Thanks,

Davi

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements

Don Guillett[_4_]

Macro closes excel and therefore won't run anymore
 
Here is one I use to save all open workbooks and quit.
You can modify to suit.

Sub CLOSE_ALL()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each w In Workbooks
w.Save
Next
Application.Quit
End Sub

--
Don Guillett
SalesAid Software

"David_Stickland" wrote in
message ...

Firstly, I am a very new macro writer so please be patient!

I have written a very simple macro to save the current work sheet and
then quit excel if no other files are open:

Sub saveandquit()

ActiveWorkbook.Save
ActiveWorkbook.Close

If IsEmpty(ActiveWorkbook) = True Then
Application.Quit
Else
Application.WindowState = xlMinimized
End If

End Sub

The problem being that I can't (i.e. don't want to) store the macro in
my personal.xls file. If the macro is saved in the worksheet when the
macro shuts the worksheet, it effectively shuts itself and therefore
doesn't run the rest of the code.

Can I save the macro separately and then call it from a specified
location or is there a better way to do what I am trying to do?

Thanks,

David


------------------------------------------------
~~ Message posted from
http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements



David_Stickland[_2_]

Macro closes excel and therefore won't run anymore
 

Thanks for that.

That is a good way to work around the problem


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements


All times are GMT +1. The time now is 01:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com