Vb code to run on only authorized system while spreadsheet will still be readable by other users

jhonty4

Board Regular
Joined
May 16, 2016
Messages
85
Hi
i have created an automated excel and now i want to distribute it.
I want the excel spreadsheet to be usable to everyone who has it but the code should only run on the system which has been authorised.
My target users have limited knowledge of excel and very basic security will do the job.

Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
have a read > https://www.techonthenet.com/excel/formulas/environ.php I think there is an element in here that could ensure the could can be tested against fir your needs. Macros must be enabled
Thanks mole999
I tried this code and it works . But if the user name is changed the code will not run.
Code:
Private Sub CommandButton1_Click()

If Environ(2) = "APPDATA=C:\Users\ABC\AppData\Roaming" Then
        MsgBox "you are not authorized, the program will terminate"
        End
                
        Else
        MsgBox "You are authorized, the program will run"
  End If
  


End Sub

Is there any turnaround?
 
Last edited:
Upvote 0
I was thinking that at the top of relevant macros there would be a test that basically said if this is incorrect exit sub

If Environ(2) = "APPDATA<>C:\Users\ABC\AppData\Roaming" Then Exit Sub

there are about 300 different values that can be pulled from later versions of ENVIRONS, so path may not be the ideal. I don't know enough detail and would have to play with it to get a result I wanted
 
Upvote 0
I was thinking that at the top of relevant macros there would be a test that basically said if this is incorrect exit sub

If Environ(2) = "APPDATA<>C:\Users\ABC\AppData\Roaming" Then Exit Sub

there are about 300 different values that can be pulled from later versions of ENVIRONS, so path may not be the ideal. I don't know enough detail and would have to play with it to get a result I wanted
That's what i meant .. Path doesn't look ideal way to perform the test
Is there any way we can pull ip address and do the same code ?
 
Upvote 0
Code:
Sub Test()
On Error Resume Next

Dim LPosition As Integer

For LPosition = 1 To [B]300[/B]
   MsgBox Environ(LPosition)
Next LPosition

End Sub

you can step through this to see the multitude of options.

IP will work (if its there) until you refresh your network

if you have a standard user log in then you can use the log on name of the person
 
Upvote 0
Code:
Sub Test()
On Error Resume Next

Dim LPosition As Integer

For LPosition = 1 To [B]300[/B]
   MsgBox Environ(LPosition)
Next LPosition

End Sub

you can step through this to see the multitude of options.

IP will work (if its there) until you refresh your network

if you have a standard user log in then you can use the log on name of the person

Thanks a lot :) i'll use user log on name..
 
Upvote 0
Just found that MAC address will be better way to protect the sheet as username is also subject to change. So instead of ENVIRON i am using a code to fetch MAC address of computer.
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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