PC Review


Reply
Thread Tools Rate Thread

Disable Minimize/Maximize button for Excel 2007 Application

 
 
Steve
Guest
Posts: n/a
 
      11th Dec 2009
I am trying to prevent a workbook I made from being minimized/maximized by
the user. I have command buttons to do that and I want to force them to use
the command buttons. The code below disables the min/max application buttons
in Excel 2003, but it only disables the close button in Excel 2007. It also
disables dragging to resize the application window in 2007, but that doesn't
help me. I need to disable the min/max button and it needs to work in Excel
2007. Any suggestions?

Thanks

Steve

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
ByVal bRevert As Integer) As Integer

Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Integer, _
ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

'The following procedure disables the Control menu.
Sub Disable_Control()
Dim X As Integer, hwnd As Long
hwnd = FindWindow("XLMain", Application.Caption)
For X = 1 To 9
'Delete the first menu command and loop until
'all commands are deleted
Call DeleteMenu(GetSystemMenu(hwnd, False), 0, 1024)
Next X
End Sub

'The following procedure restores the Control menu.
'Note that to run this procedure, the Declare statements above
'must be in the module.
Sub RestoreSystemMenu()
Dim hwnd As Long
'Get the window handle of the Excel application.
hwnd = FindWindow("xlMain", Application.Caption)
'Restore system menu to original state.
hMenu% = GetSystemMenu(hwnd, 1)
End Sub
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      11th Dec 2009
Try some code like the following:


Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const GWL_STYLE = (-16)

Private Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA" ( _
ByVal HWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias
"SetWindowLongA" ( _
ByVal HWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Sub ShowMinMax(ShowMin As Boolean, ShowMax As Boolean)
Dim WinInfo As Long
WinInfo = GetWindowLong(Application.HWnd, GWL_STYLE)

If ShowMin = True Then
WinInfo = WinInfo Or WS_MAXIMIZEBOX
Else
WinInfo = WinInfo And (Not WinInfo)
End If
If ShowMax = True Then
WinInfo = WinInfo Or WS_MAXIMIZEBOX
Else
WinInfo = WinInfo And (Not WS_MAXIMIZEBOX)
End If
SetWindowLong Application.HWnd, GWL_STYLE, WinInfo
End Sub



Cal the ShowMinMax proc passing it values indicating whether to show
or hide the min and max buttons.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Fri, 11 Dec 2009 11:47:01 -0800, Steve
<(E-Mail Removed)> wrote:

>I am trying to prevent a workbook I made from being minimized/maximized by
>the user. I have command buttons to do that and I want to force them to use
>the command buttons. The code below disables the min/max application buttons
>in Excel 2003, but it only disables the close button in Excel 2007. It also
>disables dragging to resize the application window in 2007, but that doesn't
>help me. I need to disable the min/max button and it needs to work in Excel
>2007. Any suggestions?
>
>Thanks
>
>Steve
>
>Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
> (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
>
>Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
> ByVal bRevert As Integer) As Integer
>
>Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Integer, _
> ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
>
>'The following procedure disables the Control menu.
>Sub Disable_Control()
> Dim X As Integer, hwnd As Long
> hwnd = FindWindow("XLMain", Application.Caption)
> For X = 1 To 9
> 'Delete the first menu command and loop until
> 'all commands are deleted
> Call DeleteMenu(GetSystemMenu(hwnd, False), 0, 1024)
> Next X
>End Sub
>
>'The following procedure restores the Control menu.
>'Note that to run this procedure, the Declare statements above
>'must be in the module.
>Sub RestoreSystemMenu()
> Dim hwnd As Long
> 'Get the window handle of the Excel application.
> hwnd = FindWindow("xlMain", Application.Caption)
> 'Restore system menu to original state.
> hMenu% = GetSystemMenu(hwnd, 1)
>End Sub

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      11th Dec 2009
There are a few typos in my previous reply. Use the following code
instead.

Sub ShowMinMax(ShowMin As Boolean, ShowMax As Boolean)
Dim WinInfo As Long
WinInfo = GetWindowLong(Application.HWnd, GWL_STYLE)

If ShowMin = True Then
WinInfo = WinInfo Or WS_MINIMIZEBOX
Else
WinInfo = WinInfo And (Not WS_MINIMIZEBOX)
End If
If ShowMax = True Then
WinInfo = WinInfo Or WS_MAXIMIZEBOX
Else
WinInfo = WinInfo And (Not WS_MAXIMIZEBOX)
End If
SetWindowLong Application.HWnd, GWL_STYLE, WinInfo
End Sub


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Fri, 11 Dec 2009 16:14:31 -0600, Chip Pearson <(E-Mail Removed)>
wrote:

>Try some code like the following:
>
>
>Private Const WS_MAXIMIZEBOX = &H10000
>Private Const WS_MINIMIZEBOX = &H20000
>Private Const GWL_STYLE = (-16)
>
>Private Declare Function GetWindowLong Lib "user32" Alias
>"GetWindowLongA" ( _
> ByVal HWnd As Long, _
> ByVal nIndex As Long) As Long
>
>Private Declare Function SetWindowLong Lib "user32" Alias
>"SetWindowLongA" ( _
> ByVal HWnd As Long, _
> ByVal nIndex As Long, _
> ByVal dwNewLong As Long) As Long
>
>Sub ShowMinMax(ShowMin As Boolean, ShowMax As Boolean)
> Dim WinInfo As Long
> WinInfo = GetWindowLong(Application.HWnd, GWL_STYLE)
>
> If ShowMin = True Then
> WinInfo = WinInfo Or WS_MAXIMIZEBOX
> Else
> WinInfo = WinInfo And (Not WinInfo)
> End If
> If ShowMax = True Then
> WinInfo = WinInfo Or WS_MAXIMIZEBOX
> Else
> WinInfo = WinInfo And (Not WS_MAXIMIZEBOX)
> End If
> SetWindowLong Application.HWnd, GWL_STYLE, WinInfo
>End Sub
>
>
>
>Cal the ShowMinMax proc passing it values indicating whether to show
>or hide the min and max buttons.
>
>Cordially,
>Chip Pearson
>Microsoft MVP 1998 - 2010
>Pearson Software Consulting, LLC
>www.cpearson.com
>[email on web site]
>
>
>
>
>On Fri, 11 Dec 2009 11:47:01 -0800, Steve
><(E-Mail Removed)> wrote:
>
>>I am trying to prevent a workbook I made from being minimized/maximized by
>>the user. I have command buttons to do that and I want to force them to use
>>the command buttons. The code below disables the min/max application buttons
>>in Excel 2003, but it only disables the close button in Excel 2007. It also
>>disables dragging to resize the application window in 2007, but that doesn't
>>help me. I need to disable the min/max button and it needs to work in Excel
>>2007. Any suggestions?
>>
>>Thanks
>>
>>Steve
>>
>>Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
>> (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
>>
>>Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
>> ByVal bRevert As Integer) As Integer
>>
>>Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Integer, _
>> ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
>>
>>'The following procedure disables the Control menu.
>>Sub Disable_Control()
>> Dim X As Integer, hwnd As Long
>> hwnd = FindWindow("XLMain", Application.Caption)
>> For X = 1 To 9
>> 'Delete the first menu command and loop until
>> 'all commands are deleted
>> Call DeleteMenu(GetSystemMenu(hwnd, False), 0, 1024)
>> Next X
>>End Sub
>>
>>'The following procedure restores the Control menu.
>>'Note that to run this procedure, the Declare statements above
>>'must be in the module.
>>Sub RestoreSystemMenu()
>> Dim hwnd As Long
>> 'Get the window handle of the Excel application.
>> hwnd = FindWindow("xlMain", Application.Caption)
>> 'Restore system menu to original state.
>> hMenu% = GetSystemMenu(hwnd, 1)
>>End Sub

 
Reply With Quote
 
New Member
Join Date: Mar 2011
Posts: 1
 
      2nd Mar 2011
Hi,
I'm also facing the similar Problem. In Office 2010 I'm able to disable only the Close button but not the Min Max button. While loading the excel sheet ur code Works fine but once the sheet is loaded i'm not able disable min max buttons.I'm enabling ribbon to show the Print Preview after that i'm not able to disable the min max buttons. I called the Same Process what we followed while in load.

Please help me.

Thanks,
Aditya.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show/Hide Minimize/Maximize Button in Excel 2007/2010 usnewmansNOSPAM@charter.net Microsoft Excel Programming 2 23rd Jan 2011 07:07 PM
Disable Maximize/Minimize/Restore in Access 2007 evenlater Microsoft Access 0 20th May 2008 04:37 PM
How to disable Maximize, Minimize, Restore on windows.... =?Utf-8?B?Qm9ic29u?= Windows XP General 5 23rd Apr 2007 08:56 PM
Disable animate on maximize/minimize Chuck Windows XP Customization 1 1st Feb 2007 06:38 PM
DISABLE MAXIMIZE BUTTON on ACCESS APPLICATION =?Utf-8?B?RGFu?= Microsoft Access VBA Modules 0 5th Jul 2006 03:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:47 AM.