Excel VBA - remove/hide or change the color of title bar of a UserForm

preview_player
Показать описание
How to remove the title bar or the menu bar of a UserForm?
How to change the colour of title bar of a UserForm without effecting the system's window?
Simple hack the customize the title bar or the menu bar of a UserForm without effecting the system.

-----------------------------------------------------------------------------------------------------------------------
Code:
Option Explicit
Option Private Module

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
-----------------------------------------------------------------------------------------------------------------------

Other Functions/Properties:
1. Me.Height
2. Me.Width

File password 👉 AhSingMenu

Welcome to join and feel free to raise/ask questions (if any) or share Excel tricks 🤗

#excel #vba
Рекомендации по теме
Комментарии
Автор

Take note that, we might be facing three issues/problems when using the code. Kindly follow the suggestions given in the video to get the problems solved. Hope you like this video. Thanks for watching and have a nice day.

Code:
Option Explicit
Option Private Module

Public Const GWL_Style = -16
Public Const WS_Caption =

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

ahsing_excel_VBA
Автор

Both the videos are great answered every problem I had and that I didnt know I was even going to have thanks alot man very informative

AJ-mfqk
Автор

Hello nice video, is working for me UserForm1 but is not working for me UserForm2 and Userform3, can you help me

laplante
Автор

Thank you so much Sr. Improve your channel.

pecadvancelevel
Автор

There is another way to adjust the userform's size after removing the title bar:

dim ih!, iw!
ih = Me.insideheight: iw = Me.insidewidth

RemoveTitleBar Me

Me.height = ih: Me.width = iw

So u don't have to find borders width and title bar height manually to resize the userform.
Maybe someone will find this useful

Dyxacm