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
5,999
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,082,126
Messages
5,363,321
Members
400,725
Latest member
excelingtolearn

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top