Vba recognize first time startup

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
Does anyone know how to write coding such that excel will recognize the first time a particular file is opened on a computer?

Situation- I have a fairly self-automated workbook/program I’ve written that does a lot on its own with menus and calculations and all- all written in vba- but I’d like excel to recognize the first time a file is put on a machine (I.e. transferred via jump drive or email download) and to therefore open a userform that otherwise wouldn’t be available (I.e. someone can “initialize” the program with their name and credentials and such). Make sense?
 
@Tetra201

Ok So I've come back to finally wrapping this up and I've tweaked it. I'm failing with the 'Sheets' .select piece (I want it to go to the 'Notes' sheet and make it visible....)
but the idea now is that the ThisWorkbook calls for the "DemoTest" when the workbook opens and the demotest is below. This should check for a registration and if it exists, then it 1. Does nothing or 2. If the activesheet is on Notes (i.e. the user opens the "Notes" tab), then it says "Welcome back blah blah."

However, if the registration doesn't exist upon first opening, this automatically directs the user to the "Notes" sheet after having them input a name.

Rich (BB code):
Sub DemoTest()    Dim s As String    s = GetSetting("DemoTest", "Registration", "UserName")    If s = "" Then        s = InputBox("Please enter your name:")        If s <> "" Then SaveSetting "DemoTest", "Registration", "UserName", s        If s <> "" Then Sheets("Notes").Select
        If s <> "" Then Sheets("Notes").Visible = True    Else        If Activesheet.name = "Notes" Then
        MsgBox "Welcome back, " & s    End IfEnd Sub




 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I've also tried this:

Code:
 DemoTest()
'First time initializing Code
Dim s As String
Dim name As String
name = Sheets("Notes").Range("N4")
s = GetSetting("DemoTest", "Registration", "Username")
    If s = "" Then
        s = InputBox("Please enter your name:", name)
        If s <> "" Then SaveSetting "DemoTest", "Registration", "Username", s
        If s <> "" Then Sheets("Notes").Select
        If s <> "" Then Sheets("Notes").Visible = True
    ElseIf Sheets("Notes").Select = True Then MsgBox "Welcome Back, " & s, , name
    Else
        If ActiveSheet.name = "Notes" Then
        MsgBox "Welcome Back, " & s, , name
        End If
    End If
End Sub
 
Upvote 0
Maybe
Code:
Sub DemoTest()
    Dim s As String
    Dim name As String
    name = Sheets("Notes").Range("N4")
    s = GetSetting("DemoTest", "Registration", "Username")
    If s = "" Then
        s = InputBox("Please enter your name:", name)
        If s <> "" Then
            SaveSetting "DemoTest", "Registration", "Username", s
            Sheets("Notes").Visible = xlSheetVisible
            Sheets("Notes").Select
        End If
    ElseIf ActiveSheet.name = "Notes" Then
        MsgBox "Welcome Back, " & s, , name
    End If
End Sub
 
Upvote 0
So code worked like a champ!

now as I continue tweaking- I have an textbox on Userform17. I tried adding the below to see if that would work but it obviously didn't.
Code:
s = Userform17.TextBox1.Value
 
Upvote 0
On a secondary note, I tried the following modifications to attempt a "date" initialization for locking out the workbook using a date. This is in addition to having the "name" in place.

Code:
Sub DemoTestDate()
Dim s as String
Dim name as String
Dim resp as Integer
Dim cdate as String
Dim ddate as String
name = Sheets("Notes").Range("N4")
cdate = Sheets("Developer").Range("A34") 'where A34 is C34+E34
ddate = Sheets("Developer").Range("C34") 'where C34 is a date (manually typed in) and E34 is a manual number of days, say 30

s = GetSetting("DemoTestDate", "Registration", "Username")

If s = "" Then
s = Date

ElseIf s > cdate Then
If s <> "" Then 
SaveSetting "DemoTestDate", "Registration", "Username", s 
End If 

ElseIf s < cdate Then
resp = MsgBox("This is expired, vbYesNo, name)
If resp = Yes Then
ddate = date
If resp = No Then Exit Sub
End If

End If 
'lesson learned- don't manually type out code when you could just copy and paste.....
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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