Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
| Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 12th, 2007, 07:37 AM
Registered User
Join Date: May 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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,

Old May 16th, 2007, 03:50 PM
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...

Similar Threads
Thread Thread Starter Forum Replies Last Post
File Sharing lock count exceeded williamlove Access 11 August 3rd, 2018 02:44 AM
CanĀ“t creat excel file on a PC using ASP rtr1900 ASP.NET 2.0 Basics 6 October 29th, 2008 03:00 AM
VC++ 2005 PC ERROR @ PC STARTUP -JUST IN TIME DBUG CPPGUY Visual C++ 2005 0 October 3rd, 2008 12:52 PM
lock folder or file siva_garlapati Biztalk 2 January 16th, 2006 09:23 AM
file transfer ftp server to a pocket PC in C# .NET g_hristodol ADO.NET 0 October 21st, 2004 06:14 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.