I am trying to create a security system for an Excel file that I want to sell, I want this file to execute a function only the first time it is opened to obtain the username and IP address of the client, these are saved and the following times that the file is opened compare if it is the same user, In case of being the same can see the content, in case of being another person can not see anything of the file, in this way the client can not share the Excel.
At the moment I have this that works, but I need to ask the client his team name, the idea is that he gets it alone.
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim hoja As Worksheet
Sheets("Hoja1").Visible = xlSheetVisible
For Each hoja In ThisWorkbook.Worksheets
If hoja.Name <> "Hoja1" Then
hoja.Visible = xlSheetVeryHidden
End If
Next hoja
ActiveWorkbook.Save
End Sub
Private Sub Workbook_Open()
Dim nombreEquipo As String
' Obtener nombre de equipo
nombreEquipo = Environ$("computername")
If "DESKTOP-I8NVLS9" <> nombreEquipo Then ActiveWorkbook.Close
Dim hoja As Worksheet
For Each hoja In ThisWorkbook.Worksheets
hoja.Visible = xlSheetVisible
Next hoja
Sheets("Hoja1").Visible = xlSheetVeryHidden
End Sub
I found this code but it is in vb.net.
How to run a function on first run?
If My.Settings.IsFirstTimeRun Then
System.Console.WriteLine("Hello, what is your name?")
' Update and save the value of the setting.
My.Settings.IsFirstTimeRun = False
My.Settings.Save()
Else
System.Console.WriteLine("Welcome back!")
End If