sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
So I have some code here that is beating my in the head.
The code is supposed to open up the workbook, immediately making it not visible. Then, it should go, check the registry. If the user has not made a "name" before, it should show Userform17. Userform17 has a single input box (Userform17.TextBox1.Value) that should become the "name" for the registry. This name should also populate cell B34:F34 and it should throw today's date into cell C36. If the program is already "Registered," then it should skip ahead and see if the date in cell E37 is greater than or equal to today. If it is not, it should kick out with an Inputbox that requests a "registration key" which is just a string of numbers in cell B39. If the correct string is put in, then cell C36 should be given today's date. Now if the program is registered, the date in cell E37 is greater than or equal to today, the the program should show one of three userforms (1, 2, or 3) dependent on the name of the workbook.
However, currently the program is showing Userform17 every time it opens, it not populating B34 nor "registering" the program, and is not showing the appropriate userform after all of this. Ideas? Thanks for taking a look!
The code is supposed to open up the workbook, immediately making it not visible. Then, it should go, check the registry. If the user has not made a "name" before, it should show Userform17. Userform17 has a single input box (Userform17.TextBox1.Value) that should become the "name" for the registry. This name should also populate cell B34:F34 and it should throw today's date into cell C36. If the program is already "Registered," then it should skip ahead and see if the date in cell E37 is greater than or equal to today. If it is not, it should kick out with an Inputbox that requests a "registration key" which is just a string of numbers in cell B39. If the correct string is put in, then cell C36 should be given today's date. Now if the program is registered, the date in cell E37 is greater than or equal to today, the the program should show one of three userforms (1, 2, or 3) dependent on the name of the workbook.
However, currently the program is showing Userform17 every time it opens, it not populating B34 nor "registering" the program, and is not showing the appropriate userform after all of this. Ideas? Thanks for taking a look!
Code:
Private Sub Workbook_Open()
'This will show the Userform 1 when starting and hide the excel sheet in the background
'Also checks to see if program has ever been run, and if not, loads program for the first time
Application.Visible = False
Dim s As String
Dim edate As String
Dim namer As String
Dim d As String
d = Sheets("Developer").Range("B39") 'registration key
edate = Sheets("Developer").Range("E37") 'expiration date
namer = Sheets("Notes").Range("N4") 'just a name
s = GetSetting("DemoTest", "Registration", "Username")
If s = "" Then
s = InputBox("Please enter your name:", name) 'I really don't want the inputbox. I really want the userform
'UserForm17.Show
If s <> "" Then
's = UserForm17.TextBox1.Value
Sheets("Developer").Range("B34") = s
SaveSetting "DemoTest", "Registration", "Username", s
Sheets("Notes").Visible = xlSheetVisible
Sheets("Notes").Select
Sheets("Developer").Range("C36") = Today
'If s <> "" Then MsgBox "Welcome to the " & name & " Voyage Reporting System." & vbCrLf & "Please input the appropriate data to initialize the system for the first time." & vbCrLf & vbCrLf & "Note: this information can be modified later by clicking on the [Developer] button.", vbOKOnly, name
Application.Visible = True
End If
Else:
If ExpirationDate = edate Then
If Now() < ExpirationDate 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: d = Application.InputBox("Your workbook date has expired. Please enter the registration key to renew your license.", namer)
If d = CStr(Worksheets("Developer").Range("B39").Value) Then
Sheets("Developer").Range("C36") = Today
MsgBox "Welcome Back", vbOKOnly, namer
End If
End If
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
End Sub