Set device limit for excel with vba

sekhar03

New Member
Joined
Jul 26, 2020
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I've an Excel sheet and I want to set limit on number of computers that the workbook can be accessed.
Every time the Excel workbook opened my vba script should collect the computer name. If the computer name is not part of earlier list then auto increment. Limit should be exceeded if excel accessed in more than 6 computers.
Here, my intention is to Excel sheet can be accessed only in 6 different computers.

Can we have vba script for the same.?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Yes, you can do that with VBA. However, this is a forum with volunteers, this question sounds like a paid job. From the forum rules: If you have an urgent need, check the Consulting Services page.
 
Upvote 0
However, I've figured out the way to limit computers.
Would you mind posting your solution?
That way if others have similar questions, and find this thread, it might help them out.
 
Upvote 0
This can be achieved by using Remove duplicate option. Every time user opens the file, we'll be storing their computer name in a sheet (which is hidden to user) and remove duplicates to make sure we are not single computer name multiple times. We'll be counting the rows after removing duplicates. If the count is beyond our specified limit then we can display a message saying limit exceeded and close the active workbook.

Here, we are protecting the sheet and and VBA code from user. Here is the code.

This code might sound silly but this level of security will be enough for my purpose. There might be better solutions as well. If you have any such, post here.

Private Sub Workbook_Open()

'Getting computer name
ComputerName = Environ("computername")

'Getting user name
UserName = Environ("username")

LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row 'Getting Last row from active sheet
Cells(LastRow + 1, 1) = ComputerName 'Storing the computer name in the last cell
ActiveSheet.Range("A1:A100").RemoveDuplicates Columns:=1, Header:=xlNo ' Removing Dups
usedRows = ActiveSheet.UsedRange.Rows.Count
'MsgBox (usedRows)
If usedRows >= 1000 Then
MsgBox ("Device limit exceeded: " & usedRows)
ActiveWorkbook.Close savechanges:=False

End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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