show userform based on password by inputbox

KalilMe

Active Member
Joined
Mar 5, 2021
Messages
354
Office Version
  1. 2016
Platform
  1. Windows
Hi experts ,
I have commandbutton inside sheet is linked with userform1

I want before run userform should show inputbox and enter password "ATS-122#$%DF" if it's matched then will show userform , if it's not pops message box " error password " after three tries to try show userform , then should pops up message " sorry your tries run out " and close the excel file(( not close others files are open) .
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hello @KalilMe . Thanks for posting on the forum.

Please put ALL of the following code in a module. (including the first lines).
Change UserForm1 to the name of your userform.
VBA Code:
Option Explicit

Dim nCount As Long

Sub show_userform()
  Dim pwd As String
  Do While True
    pwd = InputBox("Enter Password", "USERFORM")
    If StrPtr(pwd) = 0 Then
      MsgBox "Click Cancel, exit now"
      Exit Sub
    ElseIf Len(pwd) = 0 Then
      MsgBox "Please enter pwd"
    Else
      If pwd = "ATS-122#$%DF" Then
        UserForm1.Show
      Else
        nCount = nCount + 1
        If nCount = 3 Then
          MsgBox "Sorry your tries run out"
          ThisWorkbook.Close
        End If
        MsgBox "Error password"
      End If
    End If
  Loop
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 1
Solution

Forum statistics

Threads
1,223,360
Messages
6,171,631
Members
452,411
Latest member
sprichwort

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top