View Single Post
  #2 (permalink)  
Old May 16th, 2007, 03:50 PM
ph23ms ph23ms is offline
Registered User
Join Date: May 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

i would personally use a combination of returns from ENVIRON() function... Firstly put something into the This Workbook Module...

find out the name of your pc first, either by going to control panel or with:

Sub KwikNDirty()
Msgbox ENVIRON("Computername")
End Sub
Make a note of it somewhere, as this will have to be hardwired in the code... This means that you will be pretty screwed if you change PC name for whatever reason... I would suggest taking a backup and putting it in a secure place... :D

Private Sub Workbook_Open()
Dim ChkName As String  'will contain hard-wired name

ChkName = MY-PC      'hard-wired name for example = MY-PC

If Environ("Computername") <> ChkName Then

    MsgBox "File is only available to PC: " & ChkName, _
        vbCritical + vbOKOnly, "Cannot Open File"
    Application.DisplayAlerts = False

    Exit Sub


    MsgBox "PC security check passed.", vbOKOnly + _
        vbInformation, "File Open Succesful"

End If

End Sub
One issue with this being that if the security level is set above anything but low it will produce a dialog asking whether to enable macros before the workbook opens... If you choose Disable Macros, it doesnt run the check anyway...

Obviously you could just password protect the file... It depends how you intend to use the file.. Also bear in mind that Excel passwords can be cracked...

Hope some of this helps...

Reply With Quote