Remove Userform Caption And Make Modeless

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
I got this code from another thread and the code is great EXCEPT, I would like my userform to be modeless.

I changed the script to vbmodeless but the form is still locked in modal mode.

Any help would be appreciated

Code:
*** Place this code In a User Form *** 
 
Option Explicit 
 
Private Sub UserForm_Initialize() 
     
    Call RemoveCaption(Me) 
     
End Sub 
 
*** Place this code In a Module *** 
 
Option Explicit 
 
Private Declare Function FindWindow Lib "User32" _ 
Alias "FindWindowA" ( _ 
ByVal lpClassName As String, _ 
ByVal lpWindowName As String) As Long 
 
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 
 
Private Declare Function DrawMenuBar Lib "User32" ( _ 
ByVal hwnd As Long) As Long 
 
Sub RemoveCaption(objForm As Object) 
     
    Dim lStyle          As Long 
    Dim hMenu           As Long 
    Dim mhWndForm       As Long 
     
    If Val(Application.Version) < 9 Then 
        mhWndForm = FindWindow("ThunderXFrame", objForm.Caption) 'XL97
    Else 
        mhWndForm = FindWindow("ThunderDFrame", objForm.Caption) 'XL2000+
    End If 
    lStyle = GetWindowLong(mhWndForm, -16) 
    lStyle = lStyle And Not &HC00000 
    SetWindowLong mhWndForm, -16, lStyle 
    DrawMenuBar mhWndForm 
     
End Sub 
 
Sub ShowForm() 
     
    UserForm1.Show False 
     
End Sub
 

repairman615

Well-known Member
Joined
Dec 21, 2009
Messages
1,885
To double check, near the bottom you tried:

<font face=Courier New>UserForm1.Show (vbModeless)</FONT>

other than that I may not be much help.
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
Thanks repairman, yes I tried it but for some reason within the API script it must lock the form to modal, I guess so that the form is the foremost front window, but not entirely sure.
 

repairman615

Well-known Member
Joined
Dec 21, 2009
Messages
1,885
Well this next bit is totally a guess..

What if you were to place:

<font face=Courier New>Me.Show (vbModeless)</FONT>

after
Call RemoveCaption(Me)

??

Code:
Private Sub UserForm_Initialize() 
     
    Call RemoveCaption(Me) 
    Me.Show (vbModeless)
End Sub
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
It still remains modal, I'm guessing that a part of the API script locks it and therefore would need to be changed, but I have absolutely no knowledge about API's.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,059
Try putting the
Code:
Sub ShowUserForm()
    UserForm1.Show vbModeless
End Sub
in a standard module or sheet module rather than the UserForm1 module.
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
Still no joy, If I put the script in it's own module it is now removing the actual excel title bar rather than the userform title bar.
 

Forum statistics

Threads
1,085,294
Messages
5,382,771
Members
401,804
Latest member
RB85

Some videos you may like

This Week's Hot Topics

Top