not for the newbies...

  • Thread starter Thread starter Tereba
  • Start date Start date
T

Tereba

Hi

I need help in figuring this out...

Is there a command in Excel VBA where I can disable the
buttons on the top right-hand corner of the program
(Minimize, Maximize and Close) ?

Any suggestions are welcome...

Thanks
Tereba
 
I haven't yet succeded in getting rid of the "Close" button but I'll le
you know if I do. In the meantime, this is to get rid of the resiz
buttons:

Workbooks(1).Windows("Book1.xls").EnableResize = False

- Piku
 
Thanks Pikus...
One thing I found out: if you go to the menu and
enable "Protect Workbook" all three buttons are gone...
Tereba
 
That's great! I recorded myself a macro and found that the same thing
can be done in VBA if necessary with this line:

ActiveWorkbook.Protect Structure:=True, Windows:=True

That's a great question and I'm glad to know the answer. Thanks for
asking it. - Pikus
 
I did'nt try to use it for excel but here is something which I use in
Access to disable the close button. Following code is a class module. I
think with a small adaptation it could be useful :

Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As
Long, ByVal bRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As
Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
'Private Declare Function GetMenuItemInfo Lib "user32" Alias
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As
Long, lpMenuItemInfo As MENUITEMINFO) As Long
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&

Public Property Get Enabled() As Boolean
Dim hWnd As Long
Dim hMenu As Long
Dim result As Long
Dim MI As MENUITEMINFO

MI.cbSize = Len(MI)
MI.dwTypeData = String(80, 0)
MI.cch = Len(MI.dwTypeData)
MI.fMask = MF_GRAYED
MI.wID = SC_CLOSE
hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
result = GetMenuItemInfo(hMenu, MI.wID, 0, MI)
Enabled = (MI.fState And MF_GRAYED) = 0
End Property

Public Property Let Enabled(boolClose As Boolean)
Dim hWnd As Long
Dim wFlags As Long
Dim hMenu As Long
Dim result As Long

hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
If Not boolClose Then
wFlags = MF_BYCOMMAND Or MF_GRAYED
Else
wFlags = MF_BYCOMMAND And Not MF_GRAYED
End If
result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Property
 
Back
Top