Well, one option is to have a list of the computer ID's that you "approve", and in the Workbook_Open() event, read the computer's ID, and If it doesn't find a match in your list, close the file.
How can I block an excel file, I mean I just want to be use in certain computers; that if anybody copies the file to another computer it won't work.
Hugo
Well, one option is to have a list of the computer ID's that you "approve", and in the Workbook_Open() event, read the computer's ID, and If it doesn't find a match in your list, close the file.
Here are a couple of ways to get the names;
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
(ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
Function GetName() As String
Dim strUserName As String
strUserName = Space(255)
WNetGetUser "", strUserName, 255
GetName = Trim(strUserName)
End Function
Private Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function ComputerName()
Dim strString As String
'Create a buffer 255 should be more then enougth
strString = String(255, Chr$(0))
'Get the computer name
GetComputerName strString, 255
'remove the unnecessary Null characters = chr$(0)'s
strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1)
'Show the computer name
ComputerName = strString
End Function
HTH
Ivan
The only problem with using a workbook_open event is that the user could turn the application.events off to open the file.
HTH
DRJ
That's not the only concern... security is one tough issue when working with VBA and Excel, and the level you want to take this depends on what you need.
The Workbook_Open is the basic step in security, which could be easily "hacked" by an advanced user.
Yes your quite correct....there are other ways to by pass this.....one quick way that comes to mind is to use a small loader fileOn 2002-02-18 16:00, DRJ wrote:
The only problem with using a workbook_open event is that the user could turn the application.events off to open the file.
HTH
DRJ
that opens up this file.....ie. Workbook open protect the MAIN file then have a loader file open this up via code.....
Ivan
A technique that I use is to have a main page and have all the rest hidded and protected. Then have a userform that is called by rightclicking the mouse. This userform allows you to navigate through different pages. If I want to put a time limit for uses of my programs I put it in the workbook_beforerightclick event. That way in order to run the macro it will have to perform the checks that I state. It is not 100% foolproof since excel workbook/worksheet protection is a joke, but it works for me.
HTH
DRJ
Like this thread? Share it with others