Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I remove the "close " button from a Excel form? 3

Status
Not open for further replies.

JensKKK

Technical User
May 8, 2007
119
GB
I use a form as to display the program logo at the program start for 3 seconds. Impatient user keep clicking that close button on the right hand side of the form and then the MS Excel unload form function is tipping over.

Can I therefore disable the close form fuction?

Thanks for your help.
 
An API functions are necessary to extend userform functionality. I prefer:

Code:
Public hWnd As Long
Private lStyle As Long

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

Private Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000


Private Sub UserForm_Initialize()
With Me
    hWnd = FindWindow("ThunderDFrame", .Caption)
    lStyle = GetWindowLong(.hWnd, GWL_STYLE)
    lStyle = lStyle Xor WS_SYSMENU
    SetWindowLong .hWnd, GWL_STYLE, lStyle
    DrawMenuBar .hWnd
End With
End Sub

combo
 
Combo is this code for MS Excel.

I couldn't get it to work.

Could you explain it to me. Please.

Thank you.
 
I assumed that you run a userform (MSForms) on workbook startup. If so, add this code to its code module. It will remove the [x] button, so the rest of the form's code can completely run.
If the scenario is different, please describe it.

combo
 
Combo thanks for your help. I got it to work now. Just had to put the code in the right place.

Thanks again.
 
If you don't want to resort to API and don't mind the [x] being there, you can also simply disable it with the following code:
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
End Sub

(also in the code module of the form)

Cheers,

Roel
 
Roel that is a very useful reply.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top