Excel VBA - Disable and remove close button on UserForm

preview_player
Показать описание
How to disable the close button on UserForm?
Procedure: QueryClose
Functions: CloseMode and Cancel

How to remove the close button (the "X" on the close tab) from UserForm?
1. Make it transparent?
2. Only remove the close button?
3. Hide the title bar?

00:19 Disable close button
02:38 Set UserForm to transparent and the coding
12:33 Remove close button from title bar
12:54 Hide or remove title bar

---------------------------------------------------------------------------------------------------------------------------
Code:
Public Const GWL_Style = -16
Public Const WS_Caption = &HC00000

Public Declare Function FindWindowA Lib "user32" (ByVal lpclassname As String, ByVal lpwindowname As String) As Long
Public Declare Function GetWindowLongA Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLongA Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long

Sub RemoveTitleBar(uf As Object)
Call SetWindowLongA(FindWindowA(vbNullString, uf.Caption), GWL_Style, GetWindowLongA(FindWindowA(vbNullString, uf.Caption), GWL_Style) And Not WS_Caption)
Call DrawMenuBar(FindWindowA(vbNullString, uf.Caption))
End Sub
Рекомендации по теме
Комментарии
Автор

Hope this helps. Thanks for watching and have a nice day.

ahsingtv
Автор

Saludos ingeniero gracias por la información y abrazos desde Puerto Rico 🇵🇷 excelente

Angel_Alvarez_Concepcion