LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to disable close button in userform?

On Feb 20, 12:13*pm, "Nigel" wrote:
You have 2 choices that I know of ...

1. Simple: intercept the UserForm close event.

add the following to your UserForm

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
* *If CloseMode = 0 Then
* * *MsgBox "This option will not close the form"
* * *Cancel = 1
* *End If
End Sub

2. Include a API to remove the UserForm caption.
More complex but add this code.......

At top of UserForm module add......

'heading for caption remover
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

-------------------------------------
Add the following function to the userform code.....

Private Function HideCaptionBar()
* Dim lngHnd * *As Long
* Dim lngStyle *As Long
* Dim lngH(1) * As Long
* Const GWL_STYLE = (-16)
* Const WS_CAPTION = &HC00000
* lngH(0) = Me.Height - Me.InsideHeight
* If Val(Application.Version) 8 Then
* * lngHnd = FindWindow("ThunderDFrame", Me.Caption)
* Else
* * lngHnd = FindWindow("ThunderXFrame", Me.Caption)
* End If
* lngStyle = GetWindowLong(lngHnd, GWL_STYLE) And Not WS_CAPTION
* SetWindowLong lngHnd, GWL_STYLE, lngStyle
* DrawMenuBar lngHnd
* lngH(1) = Me.Height - Me.InsideHeight
* Me.Height = Me.Height + lngH(1) - lngH(0)
End Function

-------------------------------------------------------
In the userform initialize code add......

Call HideCaptionBar

--

Regards,
Nigel


wrote in message

...



I have a form inside my vba project. I want to disable the close
button. How to do it?- Hide quoted text -


- Show quoted text -


Wow! Done!
This is the fastest and working reply i've ever got.
Thanks a lot!
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable the Close button on a Userform Moh Excel Programming 7 December 14th 07 05:11 PM
Disable Close Button dan Excel Discussion (Misc queries) 5 September 22nd 06 07:39 PM
Disable the Close Window button of the worksheet yangyh[_7_] Excel Programming 0 September 14th 05 05:04 AM
How to disable a sheet's x(close) button? Stefi Excel Programming 4 May 6th 05 01:21 PM
Disable close button of Modeless Userform RB Smissaert Excel Programming 2 September 13th 03 09:46 PM


All times are GMT +1. The time now is 06:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"