Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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,
Kevin

Reply With Quote
  #2 (permalink)  
Old May 16th, 2007, 03:50 PM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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




Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:50 PM.


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