Block an excel file
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: Block an excel file

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    101
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #4
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,853
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #5
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  6. #6
    Guest

    Default

    On 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
    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 file
    that opens up this file.....ie. Workbook open protect the MAIN file then have a loader file open this up via code.....

    Ivan

  7. #7
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,853
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com