0
Thanks

A few words of thanks would be greatly appreciated.

VBA - Removing the red cross from a UserForm




It may be needed that the possibility for exiting a userform until all entries have been entered is prohibited, but there is still the red cross which allows the user to exit.

Use the following code to remove the cross.

In the declaration part of a UF

'to remove the cross in a user form 
 Declare Function GetWindowLongA Lib "user32" _ 
(ByVal hwnd As Long, ByVal nIndex As Long) As Long 

 Declare Function SetWindowLongA Lib "user32" _ 
(ByVal hwnd As Long, ByVal nIndex As Long, _ 
ByVal dwNewLong As Long) As Long 

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

In the initialization of the UF

Private Sub UserForm_Initialize() 
Dim hwnd As Long 
    hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X", "D") _ 
    & "Frame", Me.Caption) 
    SetWindowLongA hwnd, -16, GetWindowLongA
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « VBA - Removing the red cross from a UserForm », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

1 Comment