Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default preventing closure of active excel window

Hi,

I wish to prevent users from closing the active excel window with the
window close button (x). I would like them to use a macro-linked
button for that. Is there a way to code this into VBA such that the
(x)-button is disabled?

Thanks
Sal
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default preventing closure of active excel window

The following was supplied courtesy of Michel Pierron, you need to put it in
the workbook code. It works for me in Excel2002.

Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function GetSystemMenu& Lib "user32" _
(ByVal hWnd As Long, ByVal bRevert As Long)
Private Declare Function DeleteMenu& Lib "user32" (ByVal hMenu As Long _
, ByVal nPosition As Long, ByVal wFlags As Long)
Private Declare Function DrawMenuBar& Lib "user32" (ByVal hWnd As Long)
Private hWnd&

Private Sub Workbook_Activate()
DeleteMenu GetSystemMenu(hWnd, 0), &HF060, 0&
DrawMenuBar hWnd
End Sub

Private Sub Workbook_Deactivate()
GetSystemMenu hWnd, True
DrawMenuBar hWnd
End Sub

Private Sub Workbook_Open()
hWnd = FindWindow(vbNullString, Application.Caption)
End Sub

"cyclingsal" wrote in message
om...
Hi,

I wish to prevent users from closing the active excel window with the
window close button (x). I would like them to use a macro-linked
button for that. Is there a way to code this into VBA such that the
(x)-button is disabled?

Thanks
Sal



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default preventing closure of active excel window

Thanks Nigel
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
missing Active Window bar Gomer Fackworth New Users to Excel 4 May 28th 08 02:13 PM
Preventing scroll outside active area Ben Excel Discussion (Misc queries) 2 October 29th 06 05:26 PM
Unexpected closure of Excel Chris A Links and Linking in Excel 1 August 31st 06 08:09 PM
Active Window Question CWillis Excel Discussion (Misc queries) 4 July 19th 06 05:52 PM
Changing Excel Icon in the Active Window Aaron[_6_] Excel Programming 3 August 7th 03 09:30 AM


All times are GMT +1. The time now is 08:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"