Disabling Close button on form 
Author Message
 Disabling Close button on form

I have a floating 'Save & Close' form that is created
wqhenever a certain file is opened. This is to force users
to save and close the file using my procedure, not using
Excel's built in Save and Close features.

How can I disable the little 'X' in the top right corner
of the form to prevent users from closing my form?

Lionel



Mon, 17 Jan 2005 03:45:02 GMT  
 Disabling Close button on form
On Wed, 31 Jul 2002 12:45:02 -0700, "Lionel Fridjhon"

Quote:

>I have a floating 'Save & Close' form that is created
>wqhenever a certain file is opened. This is to force users
>to save and close the file using my procedure, not using
>Excel's built in Save and Close features.

>How can I disable the little 'X' in the top right corner
>of the form to prevent users from closing my form?

>Lionel

You don't need to. Use the form's QueryClose event instead to
determine whether the user is trying to close it using the Close
button. If they are, cancel the close. Like so:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)

If CloseMode = vbFormControlMenu Then
    Beep
    MsgBox "Please close the form using the " _
    & "appropriate command button."
    Cancel = 1
End If

End Sub

---------------------------------------------------------
Hank Scorpio

* Please keep all replies in this Newsgroup. Thanks! *



Mon, 17 Jan 2005 06:00:11 GMT  
 Disabling Close button on form

Hank

Thanks for the input.

I think I erred in describing the button.  It is actually
a floating commandbar created with the following code:

        Function CreateCloseButton()
                Dim Combar As CommandBar
                Dim strComBarName As String

 'first get rid of old Monitor buttons
        strComBarName = "Save and Close"
               For Each Combar In Application.CommandBars
                    If Combar.Name = strComBarName Then
                        CommandBars(strComBarName).Delete
                    End If
                Next Combar

'create Close Button
                 'create floating Close button
                    Application.CommandBars.Add
(Name:="Save and Close", Position:=msoBarFloating).Enabled
= True
                    Application.CommandBars("Save and
Close").Visible = True

                Set Combar = Application.CommandBars("Save
and Close")
                    With Combar
                        .Controls.Add
(Type:=msoControlButton).Caption = "Print"
                        .Controls("Print").Style =
msoButtonCaption
                        .Controls("Print").OnAction
= "PrintCurrentSheet"
                        .Controls.Add
(Type:=msoControlButton).Caption = "Save, stay open"
                        .Controls("Save, stay open").Style
= msoButtonCaption
                        .Controls("Save, stay
open").OnAction = "SaveOpenFile"
                        .Controls.Add
(Type:=msoControlButton).Caption = "Close, Do Not Save"
                        .Controls("Close, Do Not
Save").Style = msoButtonCaption
                        .Controls.Add
(Type:=msoControlButton).Caption = "Save and Close"
                        .Controls("Save and Close").Style
= msoButtonCaption
                    End With
                   Application.CommandBars("Save and
Close").Height = 50
                   Application.CommandBars("Save and
Close").Width = 0
        End Function

Can I add anything to the code at this point to do as you
suggested?
I cannot use a form as a visible form retains the focus
and prohibits the user from working on his spreadsheet.

Therefor I am using a floating Command Bar.

Can you help?

Lionel

Quote:
>-----Original Message-----
>Message unavailable



Tue, 18 Jan 2005 02:58:43 GMT  
 Disabling Close button on form
Hi Lionel:

CommandBars("Save and Close").Protection  = msoBarNoChangeVisible
--
Regards,

Vasant.


Quote:

> Hank

> Thanks for the input.

> I think I erred in describing the button.  It is actually
> a floating commandbar created with the following code:

>         Function CreateCloseButton()
>                 Dim Combar As CommandBar
>                 Dim strComBarName As String

>  'first get rid of old Monitor buttons
>         strComBarName = "Save and Close"
>                For Each Combar In Application.CommandBars
>                     If Combar.Name = strComBarName Then
>                         CommandBars(strComBarName).Delete
>                     End If
>                 Next Combar

> 'create Close Button
>                  'create floating Close button
>                     Application.CommandBars.Add
> (Name:="Save and Close", Position:=msoBarFloating).Enabled
> = True
>                     Application.CommandBars("Save and
> Close").Visible = True

>                 Set Combar = Application.CommandBars("Save
> and Close")
>                     With Combar
>                         .Controls.Add
> (Type:=msoControlButton).Caption = "Print"
>                         .Controls("Print").Style =
> msoButtonCaption
>                         .Controls("Print").OnAction
> = "PrintCurrentSheet"
>                         .Controls.Add
> (Type:=msoControlButton).Caption = "Save, stay open"
>                         .Controls("Save, stay open").Style
> = msoButtonCaption
>                         .Controls("Save, stay
> open").OnAction = "SaveOpenFile"
>                         .Controls.Add
> (Type:=msoControlButton).Caption = "Close, Do Not Save"
>                         .Controls("Close, Do Not
> Save").Style = msoButtonCaption
>                         .Controls.Add
> (Type:=msoControlButton).Caption = "Save and Close"
>                         .Controls("Save and Close").Style
> = msoButtonCaption
>                     End With
>                    Application.CommandBars("Save and
> Close").Height = 50
>                    Application.CommandBars("Save and
> Close").Width = 0
>         End Function

> Can I add anything to the code at this point to do as you
> suggested?
> I cannot use a form as a visible form retains the focus
> and prohibits the user from working on his spreadsheet.

> Therefor I am using a floating Command Bar.

> Can you help?

> Lionel
> >-----Original Message-----
> >Message unavailable



Tue, 18 Jan 2005 11:44:13 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Disable close button on forms

2. Disable close button on forms

3. Disable Access Close Button not Form Close Button?

4. How to disable the close button from a form

5. Help - Can't disable close button on user form title bar

6. Disable Min/Max/close buttons in a form

7. Disabling close button on maximized form - How?

8. Disabling the close button on a form.

9. Disable close button on maximized forms

10. Disable Close, Restore Buttons on Maximized Form


 
Powered by phpBB® Forum Software © phpBB Group