Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Removing a control
How do I remove the close control from the upper right corner of my user form?
|
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Removing a control
On Oct 8, 6:45 pm, Mekinnik
wrote: How do I remove the close control from the upper right corner of my user form? While it is possible to remove the control completely via API calls and such, it is much easier to just capture the event when the user clicks on the close button and handle it. Private Sub UserForm_QueryClose _ (Cancel As Integer, CloseMode As Integer) If CloseMode = vbFormControlMenu Then MsgBox "Hey, don't do that!!!!" Cancel = True End If End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Removing a control
On Oct 8, 4:50 pm, JW wrote:
On Oct 8, 6:45 pm, Mekinnik wrote: How do I remove the close control from the upper right corner of my user form? While it is possible to remove the control completely via API calls and such, it is much easier to just capture the event when the user clicks on the close button and handle it. Private Sub UserForm_QueryClose _ (Cancel As Integer, CloseMode As Integer) If CloseMode = vbFormControlMenu Then MsgBox "Hey, don't do that!!!!" Cancel = True End If End Sub Hello Mekinnik, Here is the API code if your are interested. Add this to Standard VBA module. Just add the statement "DisableX" to your UserForm's Activate event procedure. 'Start of Macro '================================================= ======================= 'Written: October 08, 2007 'Author: Leith Ross 'Summary: Disables the Close Box on the UserForm. Add the statement ' DisableX to the UserForm_Activate ent procedure. ' Define API Constants Public Const MF_BYPOSITION = &H400& Public Const MF_DISABLED = &H2& ' Define the API calls needed Private Declare Function GetSystemMenu _ Lib "user32.dll" _ (ByVal hWnd As Long, _ ByVal bRevert As Long) As Long Private Declare Function GetMenuItemCount _ Lib "user32.dll" _ (ByVal hMenu As Long) As Long Private Declare Function RemoveMenu _ Lib "user32.dll" _ (ByVal hMenu As Long, _ ByVal nPosition As Long, _ ByVal wFlags As Long) As Long Private Declare Function DrawMenuBar _ Lib "user32.dll" _ (ByVal hWnd As Long) As Long ' Returns the Window Handle of the Window accepting input Private Declare Function GetForegroundWindow _ Lib "user32.dll" () As Long Public Sub DisableX() Dim hWnd As Long Dim hMenu As Long, nCount As Long Dim Ret As Long ' Get the Window Handle of the active UserForm hWnd = GetForegroundWindow() ' Get handle to system menu hMenu = GetSystemMenu(hWnd, 0) ' Get number of items in menu nCount = GetMenuItemCount(hMenu) ' Remove last item from system menu (last item is 'Close') Ret = RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION) ' Redraw menu Ret = DrawMenuBar(hWnd) End Sub '================================================= ======================= 'End of Macro Sincerely, Leith Ross |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Removing a control
On Oct 8, 4:50 pm, JW wrote:
On Oct 8, 6:45 pm, Mekinnik wrote: How do I remove the close control from the upper right corner of my user form? While it is possible to remove the control completely via API calls and such, it is much easier to just capture the event when the user clicks on the close button and handle it. Private Sub UserForm_QueryClose _ (Cancel As Integer, CloseMode As Integer) If CloseMode = vbFormControlMenu Then MsgBox "Hey, don't do that!!!!" Cancel = True End If End Sub Hello Mekinnik, Here is the API version to disable the "Close Box". Just add the statement "DisableX" to your UserForm's Activate event. Copy the macro code add paste it into a Standard VBA module. 'Start of Macro Code 'Written: October 08, 2007 'Author: Leith Ross 'Summary: Disables the Close Box on the UserForm. Add the statement ' DisableX to the UserForm_Activate ent procedure. ' Define API Constants Public Const MF_BYPOSITION = &H400& Public Const MF_DISABLED = &H2& ' Define the API calls needed Private Declare Function GetSystemMenu _ Lib "user32.dll" _ (ByVal hWnd As Long, _ ByVal bRevert As Long) As Long Private Declare Function GetMenuItemCount _ Lib "user32.dll" _ (ByVal hMenu As Long) As Long Private Declare Function RemoveMenu _ Lib "user32.dll" _ (ByVal hMenu As Long, _ ByVal nPosition As Long, _ ByVal wFlags As Long) As Long Private Declare Function DrawMenuBar _ Lib "user32.dll" _ (ByVal hWnd As Long) As Long ' Returns the Window Handle of the Window accepting input Private Declare Function GetForegroundWindow _ Lib "user32.dll" () As Long Public Sub DisableX() Dim hWnd As Long Dim hMenu As Long, nCount As Long Dim Ret As Long ' Get the Window Handle of the active UserForm hWnd = GetForegroundWindow() ' Get handle to system menu hMenu = GetSystemMenu(hWnd, 0) ' Get number of items in menu nCount = GetMenuItemCount(hMenu) ' Remove last item from system menu (last item is 'Close') Ret = RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION) ' Redraw menu Ret = DrawMenuBar(hWnd) End Sub 'End of Macro Code Sincerely, Leith Ross |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Add-In Toolbar Control - Removing The Toolbar Question | Excel Programming | |||
Removing hyperlink without removing the font settings /border sett | Excel Programming | |||
Removing patterns without removing gridlines | Excel Discussion (Misc queries) | |||
Removing calendar control | Excel Discussion (Misc queries) | |||
Calendar Control: Can't exit design mode because control can't be created | Excel Programming |