Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disable Excel Close Button

2 views
Skip to first unread message

Peter Emmenegger

unread,
Jul 30, 1999, 3:00:00 AM7/30/99
to
Hi,

I'm using Excel as a reporter where the customer can view the data. I need
to be able to disable the close button or hide it for a variety of reasons.

Does anyone know how this can be done using VBA/ActiveX?

Peter Emmenegger


David Hager

unread,
Jul 30, 1999, 3:00:00 AM7/30/99
to

This solution was posted recently by Andrew Baker.


**********************

Send in Me.Caption into either of the following routines. Make sure you do
this on the initialise event for 'DisableActiveDialogMenuControls'

'-----------------------------Declarations to Remove Dialog Controls
Private Const MF_BYPOSITION As Long = &H400 ''' Deletes the menus by
position (this is our default).
Private Const MF_BYCOMMAND As Long = &H0 ''' Deletes the menu by
Command ID. This is rarely used and is shown here for information purposes
only.
Private Const mlNUM_SYS_MENU_ITEMS As Long = 9 ''' This is the number of
items on the system menu
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long,
ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal
nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As
String, ByVal lpWindowName As String) As Long


' Comments: Deletes the system control menu of the specified window.
'
' Arguments: DialogCaption The caption of the window whose control
' menu you want to delete. If not specified,
' Application.Caption is assumed.
'
Public Sub DisableActiveDialogMenuControls(DialogCaption As String)
Dim lHandle As Long, lCount As Long
On Error Resume Next
DialogCaption = DialogCaption & vbNullChar
lHandle = FindWindowA(vbNullString, DialogCaption)
' Only continue if the passed window handle isn't zero.
If lHandle <> 0 Then
' There are 9 items on the application control menu.
' Loop through and disable each one.
For lCount = 1 To mlNUM_SYS_MENU_ITEMS
' The nPosition of the DeleteMenu function will always be 0,
' because as we delete each menu item, the next one moves up
' into the first position (index of 0).
DeleteMenu GetSystemMenu(lHandle, False), 0, MF_BYPOSITION
Next lCount
End If
End Sub

' Comments: Restores the system control menu of the specified window.
'
' Arguments: szCaption (Optional) The caption of the window whose control
' menu you want to delete. If not specified,
' Application.Caption is assumed.
'
Public Sub EnableActiveDialogMenuControls(DialogCaption As String)
Dim lHandle As Long
On Error Resume Next
DialogCaption = DialogCaption & vbNullChar
lHandle = FindWindowA(vbNullString, DialogCaption)
' Passing True to the bRevert argument of the GetSystemMenu API restores
' the control menu of the specified window.
GetSystemMenu lHandle, True
End Sub

Regards,

Andrew Baker.

STATPRO GROUP PLC


**********************

David Hager
MVP - Microsoft Excel
Baton Rouge, La.


Peter Emmenegger wrote in message ...

0 new messages