Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Form with no Cancel option

I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this Cancelbutton?

Anne


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Form with no Cancel option

Anne,

One way is to intercept the X-button in the QueryClose event of the
userform. Try something like this in the QueryClose event to cancel the
event if the user attempts to close it with the X-button:

'Check if the user is trying to close the form with the X-button
If CloseMode = vbFormControlMenu Then
Cancel = True
Exit Sub
End If



--
Hope that helps.

Vergel Adriano


"Anne Schouten" wrote:

I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this Cancelbutton?

Anne



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Form with no Cancel option

I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this Cancelbutton?


I can't see a way to hide it either. You could try this work-around I guess.
Add the following to the UserForm's code window...

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Form cannot be closed at this time.", vbInformation
End If
End Sub

Any attempt to use the "X-Button" will be met with a MessageBox informing
the user the form cannot be closed at this time (you can, of course, change
the message to suit your needs).

Rick

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Form with no Cancel option

Maybe you could just call your Cancelbutton's _click event:

Option Explicit
Private Sub CommandButton2_Click()
MsgBox "closing"
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call CommandButton2_Click
End If
End Sub



Anne Schouten wrote:

I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this Cancelbutton?

Anne


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Form with no Cancel option

I would go with the QueryClose approach as others have suggested.

FWIW you could grey out and disable the X-button -

Option Explicit

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName$, _
ByVal lpWindowName$) As Long
Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu&, ByVal nPosition&, ByVal wFlags&) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd&, ByVal bRevert&) As Long

Private Const SC_CLOSE = &HF060&

Private Sub UserForm_Initialize()
Dim hWnd As Long, hMenu As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
hMenu = GetSystemMenu(hWnd, 0)
RemoveMenu hMenu, SC_CLOSE, 0
End Sub

' make sure you have a way to close the form
Private Sub CommandButton1_Click()
Unload Me
End Sub

Regards,
Peter T

"Anne Schouten" wrote in message
...
I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this Cancelbutton?

Anne






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Form with no Cancel option

I would go with the QueryClose approach as others have suggested.

FWIW you could grey out and disable the X-button -

Option Explicit

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName$, _
ByVal lpWindowName$) As Long
Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu&, ByVal nPosition&, ByVal wFlags&) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd&, ByVal bRevert&) As Long

Private Const SC_CLOSE = &HF060&

Private Sub UserForm_Initialize()
Dim hWnd As Long, hMenu As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
hMenu = GetSystemMenu(hWnd, 0)
RemoveMenu hMenu, SC_CLOSE, 0
End Sub

' make sure you have a way to close the form
Private Sub CommandButton1_Click()
Unload Me
End Sub

Regards,
Peter T

"Anne Schouten" wrote in message
...
I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this Cancelbutton?

Anne




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Form with no Cancel option

Thank you all.

The query_Close method works perfect.

The option to disable the X-button works aswel, but I don't understand the
code. Can you tell me where to find explanation for it.

Anne


"Anne Schouten" wrote in message
...
I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this Cancelbutton?

Anne




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Form with no Cancel option

The call to the FindWindow API finds the window handle of your userform,
with the search filtered to the 'classname' of Userforms (ThunderDFrame in
VBA offiice 2000+), and the form's caption.

Calls to API's GetSystemMenu and RemoveMenu are detailed in the following
links -

http://msdn2.microsoft.com/en-us/library/ms647985.aspx

http://msdn2.microsoft.com/en-us/library/ms647994.aspx

The constant SC_CLOSE is so named by convention, but could be named
anything, or simply the value &HF060& or 61536& could be passed to identify
in particular it's the close button to be removed (or greyed).

Regards,
Peter T


"Anne Schouten" wrote in message
...
Thank you all.

The query_Close method works perfect.

The option to disable the X-button works aswel, but I don't understand the
code. Can you tell me where to find explanation for it.

Anne


"Anne Schouten" wrote in message
...
I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top

righthand
corner, other macro's will give problems, so I dont want the form to be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this

Cancelbutton?

Anne






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Form with no Cancel option

Hoi Peter,

Thank you very much for your answer ans the links.

Regards,
Anne

"Peter T" <peter_t@discussions wrote in message
...
The call to the FindWindow API finds the window handle of your userform,
with the search filtered to the 'classname' of Userforms (ThunderDFrame in
VBA offiice 2000+), and the form's caption.

Calls to API's GetSystemMenu and RemoveMenu are detailed in the following
links -

http://msdn2.microsoft.com/en-us/library/ms647985.aspx

http://msdn2.microsoft.com/en-us/library/ms647994.aspx

The constant SC_CLOSE is so named by convention, but could be named
anything, or simply the value &HF060& or 61536& could be passed to

identify
in particular it's the close button to be removed (or greyed).

Regards,
Peter T


"Anne Schouten" wrote in message
...
Thank you all.

The query_Close method works perfect.

The option to disable the X-button works aswel, but I don't understand

the
code. Can you tell me where to find explanation for it.

Anne


"Anne Schouten" wrote in message
...
I made an Excelform.
If a user closes the form with the X-button (Cancel) at the top

righthand
corner, other macro's will give problems, so I dont want the form to

be
closed with this button.

In Access you can hide this button, but so far I can see that is not
possible in Excel. How can I prevent that the user uses this

Cancelbutton?

Anne








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
3 option buttons, okay, cancel, NEED the form to stay up Janis Excel Programming 2 September 1st 06 06:43 PM
Disabling 'Cancel' option when saving work (Yes/No/Cancel) [email protected] Excel Programming 0 July 11th 06 09:28 PM
problems with a form and a cancel button filo666 Excel Programming 1 April 13th 05 01:01 AM
Cancel option possible while opening a file? aiyer[_56_] Excel Programming 1 August 31st 04 10:33 PM
Option to continue or cancel Ken G[_2_] Excel Programming 3 June 7th 04 04:13 AM


All times are GMT +1. The time now is 02:09 PM.

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"