![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Posts: 97
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
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.
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
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 |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: California
Posts: 3,857
|
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 |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
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. |
|
|
|
|
|
#6 | |
|
Guest
Posts: n/a
|
Quote:
that opens up this file.....ie. Workbook open protect the MAIN file then have a loader file open this up via code..... Ivan |
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: California
Posts: 3,857
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|