sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
I've pulled an excerpt of coding from my workbook_Open coding. When the wrong password is input into the inputbox, the input box disappears and nothing happens. I have to hit the keyboard (or mouse) to have the "wrong password" msgbox popup. Further, if I click cancel, it doesn't close the workbook (no other workbooks open), rather, it does the EXACT same scenario as if it were the wrong password and hitting the mouse brings up a wrong password message. What have i done wrong here?
Thanks
Thanks
Code:
Private Sub Workbook_Open()
Application.Visible = False
Dim namer As String
Dim d As Variant
'ExpirationDate = (Sheets("Developer").Range("E37")) 'expiration date
'edate = Sheets("Developer").Range("E37")
namer = Sheets("Notes").Range("N4") 'just a name
Else:
If ExpirationDate > Date Then
If ActiveWorkbook.name = "Master Voyage Report.xlsm" Then
UserForm1.Show
ElseIf ActiveWorkbook.name = "Current Voyage Report.xlsm" Then
UserForm2.Show
Else: UserForm3.Show
End If
Else:
TryAgain:
d = InputBox("Your workbook date has expired. Please enter the registration key to renew your license.", namer)
If d = vbCancel Then GoTo Closer
If d = "" Then GoTo Wrong
If d = CStr(Worksheets("Developer").Range("B39").Value) Then
Sheets("Developer").Range("C36") = Date
MsgBox "Welcome Back " & s, vbOKOnly, namer
Else: GoTo Wrong
End If
If ActiveWorkbook.name = "Master Voyage Report.xlsm" Then
UserForm1.Show
ElseIf ActiveWorkbook.name = "Current Voyage Report.xlsm" Then
UserForm2.Show
Else: UserForm3.Show
End If
End If
'Application.Visible = True 'inserted just to check workbook
'Protects/Hides sheets on startup
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If sh.name = "Notes" Then
sh.Protect Password:=Worksheets("Developer").Range("B17:E17").Value, UserInterfaceOnly:=True
End If
If sh.name = "Ports" Then
sh.Protect Password:=Worksheets("Developer").Range("B19:E19").Value, UserInterfaceOnly:=True
End If
If sh.name = "Developer" Then
sh.Protect Password:=Worksheets("Developer").Range("B15:E15").Value, UserInterfaceOnly:=True
End If
Next sh
Exit Sub
'Closing code
Closer:
If Workbooks.Count > 1 Then
ActiveWorkbook.Close
Else: Application.Quit
End If
Exit Sub
'Wrong coding
Wrong:
MsgBox "Password Incorrect, Please try again.", vbCritical, namer
GoTo TryAgain
End Sub
Last edited: