Share via

Using a UserForm in VBA code to password protect.

Anonymous
2010-12-30T14:12:35+00:00

I have put together some code to password protect a workbook because Excel's encryption of VBA code when you password protect with Excel's built in feature causes Excel to disable my VBA code.

The problem with my UserForm, password entry form, is the X in the upper right corner of the UserForm.

By clicking on the X, one can bypass my code.

Can one eliminate the X in the upper right corner of a UserForm?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-12-30T18:19:28+00:00

I wouldn't eliminate clicking the X.  It's a natural choice for the user.

But you could just run the code associated with the cancel/quit button from that

event:

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

    If CloseMode = vbFormControlMenu Then

        Call CommandButton2_Click 'or whatever button you're using

    End If

End Sub

peeshepme wrote:

I have put together some code to password protect a workbook because Excel's encryption of VBA code when you password protect with Excel's built in feature causes Excel to disable my VBA code.

The problem with my UserForm, password entry form, is the X in the upper right corner of the UserForm.

By clicking on the X, one can bypass my code.

Can one eliminate the X in the upper right corner of a UserForm?

--

Dave Peterson

Was this answer helpful?

0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-12-31T21:42:37+00:00

    Thank you.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-12-31T21:42:18+00:00

    Thank you.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-12-30T14:33:34+00:00

    Hi

    Private Sub UserForm_QueryClose(Cancel As Integer, _

      CloseMode As Integer)

      If CloseMode = vbFormControlMenu Then

        Cancel = True

        MsgBox "Please use the Close Button!"

      End If

    End Sub

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-12-30T14:22:25+00:00

    Hi,

    Try this which also disables ALT+F4 method of closing

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

      If CloseMode = vbFormControlMenu Then

        Cancel = True

        MsgBox "Please use the EXIT button on form!"

      End If

    End Sub


    If this post answers your question, please mark it as the Answer.

    Mike H

    Was this answer helpful?

    0 comments No comments