Please somebody, Yes or No

  • Thread starter Thread starter Sahak
  • Start date Start date
S

Sahak

Is there a macro code which will not allow closing MS
Excel
with up right corner button "X", if not, how about User
Form?

Thanks,
Sahak
 
Sahak,

For a userform, add this code to stop the user closing it from the "X"

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True

End Sub

If you make your form full screen, then the user can't see the spreadsheet
behind it and cannot close that either.

Private Sub UserForm_Initialize()
With Application
Me.Top = .Top
Me.Left = .Left
Me.Height = .Height
Me.Width = .Width
End With
End Sub

HTH
Henry
 
Sahak,

Here's a yes. Sort of. Put this in the ThisWorkbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
End Sub

It will work only when macros are enabled. If you use Ctrl-Alt-Delete to
end it, you'll get a bunch of messages, and it will eventually die,
generating "nonresponsive program" error messages and stuff.

Earl Kiosterud
mvpearl omitthisword at verizon period net
 
Hi Sahak,
Feedback especially where it may be ambiguous as to whether a
specific question is answered, and and a thank you are always welcome,
but please don't change the subject title.

Those being thanked and others looking for best answers
want to see your reply in the same thread (which it was) with the
same subject, so they know it is the same thread and what is
begin replied to.

This is part of the thread:
http://google.com/[email protected]
 
Back
Top