Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable application close button - Excel 3

Status
Not open for further replies.

ChrisBurch

IS-IT--Management
Jul 3, 2001
184
AU
Excel 97.

Is there a way to disable the application close button (X in top right corner), via vba. I'm trying to force my users to close via a macro button, which resets to standard menus. I've already disabled the close button on the window, but can't find how to kill the application one.

Thanks, Chris Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
Very very easy this one - although only when you know the answer (as with all things)

In the BEFORE_CLOSE event of the workbook, enter
cancel = true

that's all
This will not stop OTHER workbooks being closed but it WILL stop the the workbook where the code lives being closed, either via the wb close x or the app close x Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Thanks Geoff,

Unfortunately I've already got it in, and it's not functioning. Maybe I've set it up wrong, my code is:-

Private Sub WorkbookBeforeClose(cancel As Boolean)
cancel = True

yada
yada
yada

end sub

I've also tried it without the boolean statement. Am I doing something silly?

Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
Interesting - I just put cancel=true as the only statement in the before close event and it worked fine

Maybe it needs to be the LAST line in the event rather than the 1st Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
I suspect that the _beforeclose code is either not in the workbook's code module, or that (as in the post above) the underscore is missing.
Rob
[flowerface]
 
Thanks Rob, it was indeed the missing underscore. Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
Thanks Geoff,

All is now working. It got interesting for a while though, the only way I could quit the application was with the task manager [flush]. But I've got arounde that and all is now well. Now as long as nobody tells my users how to hold down the shift key.......... Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top