#1   Report Post  
Posted to microsoft.public.excel.programming
tim tim is offline
external usenet poster
 
Posts: 105
Default UserForm 2

Hello,

Is there a way to eliminate the close button [X] at the
top right of the userform?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default UserForm 2

Easiest is to leave it there and use the queryclose event to manage closing
the form.

See Stephen Bullens site for API related material
You can look at his formfun.zip (uncompress to an excel file) that shows you
all the things you can do with a userform - code is accessible
http://www.bmsltd.ie/Excel/Default.htm

--
Regards,
Tom Ogilvy




"Tim" wrote in message
...
Hello,

Is there a way to eliminate the close button [X] at the
top right of the userform?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default UserForm 2

Tim,

You can manage it rather than eliminate it.

There is a QueryClose event that is invoked whenever the form is unloaded.
There are 4 close circumstances, so you can trap them and react as you see
fit. Here is some code

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Select Case CloseMode
Case vbFormControlMenu:
Cancel = True 'User has chosen the Close command from the
'Control menu on the UserForm.
Case vbFormCode:
'Unload statement invoked from code.
Case vbAppWindows:
'Current Windows session is ending.
Case vbAppTaskManager:
'Windows Task Manager is closing the
application
End Select

End Sub

In this I have shown all 4 instances, but the only one that is actioned is
the Control Menu close, the X that is, where I cancel the close. So it has
no effect when clicking the X.

You could action some of the others, but be careful, you might never be able
to close the dang thing.


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Tim" wrote in message
...
Hello,

Is there a way to eliminate the close button [X] at the
top right of the userform?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default UserForm 2

Hi Tim,

Try this,

Put below code in userform's code module.
Should work in XL-97 & onwards.



'Original Code by Stephen Bullens & modified
'Show Userform without X Button (System Menu).
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 As Long = -16

Private Const WS_SYSMENU As Long = &H80000

Dim hWndForm, iStyle As Long

Private Sub UserForm_Activate()
hWndForm = FindWindow(vbNullString, Me.Caption)
iStyle = GetWindowLong(hWndForm, GWL_STYLE)
iStyle = iStyle And Not WS_SYSMENU
SetWindowLong hWndForm, GWL_STYLE, iStyle
DrawMenuBar hWndForm
End Sub



Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
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
VBA userform jcheko Excel Worksheet Functions 1 April 24th 08 08:38 PM
UserForm CR Excel Discussion (Misc queries) 1 August 10th 05 10:26 PM
Userform Help in VBC Marcia3641 Excel Discussion (Misc queries) 1 July 23rd 05 12:10 AM
Userform Patrick Molloy Excel Programming 1 September 9th 03 12:28 AM
userform Antonov Excel Programming 1 September 2nd 03 04:25 AM


All times are GMT +1. The time now is 10:14 AM.

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

About Us

"It's about Microsoft Excel"