p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Excel VBA (http://p2p.wrox.com/forumdisplay.php?f=79)
-   -   How to lock certain excel file into one pc? (http://p2p.wrox.com/showthread.php?t=57797)

kevinace May 12th, 2007 07:37 AM

How to lock certain excel file into one pc?
 
Hi all the experts,

i am new in excel VBA. is that anyone who know how to lock certain file into one pc? in other words, is there any code can be use to prevent certain excel file being copy to another pc? your help is very much aprreciated.
thank you...

best regards,
Kevin


ph23ms May 16th, 2007 03:50 PM

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:

Code:

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

Code:

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
    ThisWorkbook.Close

    Exit Sub

Else

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






All times are GMT -4. The time now is 10:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.