Making user do something before exiting Excel

ammdumas

Active Member
Joined
Mar 14, 2002
Messages
469
I want to make sure a user has hidden columns before they exit Excel. How can I get a macros to check that it's been done when they try to close down excel in any way?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Wouldn't it be easier to just hide the columns when Excel closes?

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Sheets("Sheet1").Columns("A:D").Hidden = True
End Sub
 
Upvote 0
Didn't work. Just closes without doing anything. Hiding the coplumns is also password protected. I don't know if that would have anything to do with it....
 
Upvote 0
The code needs to go into the ThisWorkbook module. Try this instead:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    With Sheets("Sheet1")
        .Unprotect Password:="Hello"
        .Columns("A:D").Hidden = True
        .Protect Password:="Hello"
    End With
End Sub
 
Upvote 0
ammdumas said:
How do I out code into that module? Where do I find it?

From Excel, push ALT + F11 to open the Visual Basic Editor.

On the left side, you should see ThisWorkbook. Double-click this and then insert the code into the window on the right.
 
Upvote 0
You rock! It works. You know, That's a pretty good thing for everybody to know...should post it somewhere...
 
Upvote 0

Forum statistics

Threads
1,221,709
Messages
6,161,431
Members
451,705
Latest member
Priti_190

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