Disabling close button on Excel workbook window 
Author Message
 Disabling close button on Excel workbook window

Do you take issue with the use of the Protect method of the Workbook object?
If not, then below is a simplified version of a function I use...

Sub ProtectMe()
    bProtectBook ActiveWorkbook, , False
End Sub

Function bProtectBook(wkb As Workbook, Optional ByVal szPassWord As String =
"", Optional ByVal bStructure As Boolean = True, Optional ByVal bWin As
Boolean = True) As Boolean
    On Error Resume Next
    wkb.Protect Password:=szPassWord, Structure:=bStructure, Windows:=bWin
End Function

Note that in your case, I passed False for the bStructure argument so that
the user can still manipulate the sheet structure.
_______________
Robert Rosenberg
RCOR Consulting
Microsoft MVP - Excel

http://www.*-*-*.com/


Quote:
> I am trying to disable the close button on an
> Excel workbook window,at the moment by doing an
> API call from the VBA editor. The trouble is the
> code I have beneath disables the close button on
> the Excel Window itself - I want to disable it on
> the workbook window beneath it & not the Excel
> Window. Can anyone help???

> Thanks

> mel

> Code:

> Private Declare Function GetSystemMenu Lib
> "user32" (ByVal hWnd As Long, ByVal bRevert As
> Long) As Long
> Private Declare Function GetMenuItemCount Lib
> "user32" (ByVal hMenu As Long) As Long
> Private Declare Function RemoveMenu Lib "user32"
> (ByVal hMenu As Long, ByVal nPosition As Long,
> ByVal wFlags As Long) As Long
> Private Declare Function DrawMenuBar Lib "user32"
> (ByVal hWnd As Long) As Long
> Private Declare Function FindWindow Lib "user32"
> Alias "FindWindowA" (ByVal lpClassName As String _
> , ByVal lpWindowname As String) As Long 'retuns
> handle of active window

> Private Const MF_BYPOSITION = &H400&

> Private Sub DisableClose()

> Dim hInst As Long 'this returns handle of active
> window,
> hInst = FindWindow(vbNullString,
> Application.Caption)

> Dim hMenu As Long, lCnt As Long
> hMenu = GetSystemMenu(hInst, False)
> If Not False Then
> lCnt = GetMenuItemCount(hMenu)
> Call RemoveMenu(hMenu, lCnt - 1, MF_BYPOSITION)
> Call RemoveMenu(hMenu, lCnt - 2, MF_BYPOSITION) '
> Separator
> End If
> Call DrawMenuBar(hInst) ' Update changes
> 'bCloseDisabled = Not bCloseDisabled
> End Sub
> Private Sub EnableClose()

> Dim hInst As Long 'this returns handle of active
> window,
> hInst = FindWindow(vbNullString,
> Application.Caption)

> Dim hMenu As Long, lCnt As Long
> hMenu = GetSystemMenu(hInst, True)
> If Not True Then
> lCnt = GetMenuItemCount(hMenu)
> Call RemoveMenu(hMenu, lCnt - 1, MF_BYPOSITION)
> Call RemoveMenu(hMenu, lCnt - 2, MF_BYPOSITION) '
> Separator
> End If
> Call DrawMenuBar(hInst) ' Update changes

> End Sub

> Sent via Deja.com http://www.*-*-*.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Disabling close button on Excel workbook window
I am trying to disable the close button on an
Excel workbook window,at the moment by doing an
API call from the VBA editor. The trouble is the
code I have beneath disables the close button on
the Excel Window itself - I want to disable it on
the workbook window beneath it & not the Excel
Window. Can anyone help???

Thanks

mel

Code:

Private Declare Function GetSystemMenu Lib
"user32" (ByVal hWnd As Long, ByVal bRevert As
Long) As Long
Private Declare Function GetMenuItemCount Lib
"user32" (ByVal hMenu As Long) As Long
Private Declare Function RemoveMenu Lib "user32"
(ByVal hMenu As Long, ByVal nPosition As Long,
ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32"
(ByVal hWnd As Long) As Long
Private Declare Function FindWindow Lib "user32"
Alias "FindWindowA" (ByVal lpClassName As String _
, ByVal lpWindowname As String) As Long 'retuns
handle of active window

Private Const MF_BYPOSITION = &H400&

Private Sub DisableClose()

Dim hInst As Long 'this returns handle of active
window,
hInst = FindWindow(vbNullString,
Application.Caption)

Dim hMenu As Long, lCnt As Long
hMenu = GetSystemMenu(hInst, False)
If Not False Then
lCnt = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, lCnt - 1, MF_BYPOSITION)
Call RemoveMenu(hMenu, lCnt - 2, MF_BYPOSITION) '
Separator
End If
Call DrawMenuBar(hInst) ' Update changes
'bCloseDisabled = Not bCloseDisabled
End Sub
Private Sub EnableClose()

Dim hInst As Long 'this returns handle of active
window,
hInst = FindWindow(vbNullString,
Application.Caption)

Dim hMenu As Long, lCnt As Long
hMenu = GetSystemMenu(hInst, True)
If Not True Then
lCnt = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, lCnt - 1, MF_BYPOSITION)
Call RemoveMenu(hMenu, lCnt - 2, MF_BYPOSITION) '
Separator
End If
Call DrawMenuBar(hInst) ' Update changes

End Sub

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Disable Access Close Button not Form Close Button?

2. disable [x] close button on window

3. Disabling Close Window button in UserForm

4. Disabling the close button on the Access application window

5. Disabling the window's close button

6. Disable close button or hide main access window

7. Access - Disable Main DB Window Close Button

8. Disable close button or hide main access window

9. Access-Disable Main DB Window close button

10. How to disable the close window button in right corner of menu Bar in word


 
Powered by phpBB® Forum Software © phpBB Group