Macro for closing a workbook

Harvey12

Board Regular
Joined
Feb 23, 2015
Messages
130
Hi All,

I am unsure if this is possible so I will do my best to explain what I am looking for!

I am trying to write a macro which can close a workbook after another macro has been ran.

The first macro runs this unhides a selection of tabs, this is controlled through the click of a command button that runs that macro, this works fine. The next challenge is that I need that macro to be followed by some further code that will close the workbook, once that macro is complete, and only if that macro is run.

The file automatically saves itself.

Can someone please assist.

Many thanks
Harvey
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi Harvey12,

Can you not just add this line to the end of your current code?

Workbooks("WORKBOOK NAME.XLSM").Close
 
Upvote 0
Hi Fishboy,

Thanks for such rapid response, I am actually asking on behalf of someone and apparently I've asked for the wrong thing!!

What he wants to happen is once the macro has been run to unhide all of the worksheets, when someone attempts to close the workbook a message box needs to pop open, essentially he is looking for a way for another macro to run ONLY IF that macro to unhide the sheets has been run, otherwise if the sheets have no been unhidden he wants the file to close in the normal fashion?

Many thanks
Harvey
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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