Hide close [X] button on excel vba userform for my progress bar

前端 未结 6 1488
面向向阳花
面向向阳花 2020-12-28 09:27

I created a userform to show a progress bar when the macro is still importing sheets \"enter

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-28 09:46

    You can work it out from the following snippets:

    Select the cmdClose button On the Menu bar, choose View | Code Where the cursor is flashing, enter the following code:

    Private Sub cmdClose_Click()
      Unload Me
    End Sub
    

    On the Menu bar, choose View | Object, to return to the UserForm.

    To allow users to close the form by pressing the Esc key:

    Select the cmdClose button In the Properties window, change the Cancel property to True

    To prevent users from closing the form by clicking the X button

    When the UserForm is opened, there is an X at the top right. In addition to using the Close Form button, people will be able to close the form by using the X. If you want to prevent that, follow these steps.

    Right-click on an empty part of the UserForm Choose View | Code From the Procedure dropdown, at the top right, choose QueryClose

    Where the cursor is flashing, paste the highlighted code from the following sample

    Private Sub UserForm_QueryClose(Cancel As Integer, _
      CloseMode As Integer)
      If CloseMode = vbFormControlMenu Then
        Cancel = True
        MsgBox "Please use the Close Form button!"
      End If
    End Sub
    

    On the Menu bar, choose View | Object, to return to the UserForm. Now, if someone clicks the X in the UserForm, they'll see your message.

    from http://www.contextures.com/xlUserForm01.html

提交回复
热议问题