Protect Excel Worksheet to be opened on one PC only

F

Fabian

Hello,

I am looking for a solution to protect an Excel document to be opened on one
computer only. On other computers, the Excel document should show a message
like "This document cannot be opened on this computer" or just fail to open.

The idea is to protect intellectual property in that document (and to
prohibit its usage, so a simple cell protection wouldn't be enough).

Third party solutions would be OK too.

Any answers would be highly appreciated!

Thank you,
Fabian
 
K

Kevin Smith

Hello,

In the "ThisWorkbook" section in the VBE you can use this code to check the
computer ID and then unprotect the spreadsheet so that it can be edited.

Private Sub Workbook_Open()
If Not Environ("ComputerName") = "YourComputerName" Then
Application.Quit
End If
ActiveSheet.Unprotect Password:="YourPassword"
End Sub

then in the same section use ...

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveSheet.Protect Password:="YourPassword", DrawingObjects:=False,
Contents:=True, Scenarios:=True
End Sub

this will password protect your spreadsheet again when you close it.
 
F

Fabian

Hi Kevin,

thanks for your answer!

But wouldn't it be possible for the user to not execute macros and to open
the workbook then? OK, it would be protected, but it seems not completely
safe to me.

Fabian
 
K

Kevin Smith

You are correct that they can bypass the code but if you password protect the
information then all thay will be able to do is view the data rather than
edit it. on the PC that you specify you will not need to unprotect and
protect the date because that is handled in the code.

it is something that i do with excel and access, i check the ComputerName
and User Name. if it is not me then it protects the data and if it is me then
it allows me full access.
 
J

Jacob Skaria

Excel internal security is very weak and passwords can be easily cracked. No
matter how hard you try; any user with the intend of opening the files can
easily google and get a password cracker. So suggest not to use excel to
store such data...

If this post helps click Yes
 
F

Fabian

ok, thanks for the the code snippet. It could be a solution of last-resort;
problem is that the user needs to allow the Macros (we're dealing with end
users here). And I believe that the built-in Excel protection is not totally
secure (anyone has details about this)?

But anyways, thanks for your help!
 
K

Kevin Smith

No problems. Just be careful though because like Jacob said excel is weak in
security and no matter what you do to protect the information someone will be
able to get in if they wanted to.
 
K

Kevin Smith

Another option would be

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet2").Visible = xlVeryHidden
End Sub

The Very Hidden statement means that the sheet can not be displayed through
the normal options "Format-Sheets-Unhide" It can only be displayed again
through code. i.e.

Private Sub Workbook_Open()
Sheets("Sheet2").Visible = True
End Sub

If you hide the sheets on the workbook close then even if people Bypass the
code then they still will not be able to view the sheet with information on
it.
 
L

LyndaLu

I have the opposite problem. I set a password for our Excel worksheets so
only the three of us who use it could get in, and only I can . . . it doesn't
even ask them for the password . . . just says "administrator set password".
Any idea what have I done wrong? We have 2003 and I used Tools, General
Options to set the password.
Thanks for any ideas.
 
G

Gord Dibben

You did not set a pasword for the sheets.

Where you set the password was under File>Save As>Tools>General Options
password to open the file(workbook)?

You do not get a password request when you open the file?


Gord Dibben MS Excel MVP
 
L

LyndaLu

Gord, That is exactly what I did. I get the password prompt when I want to
open a file, but no one else does. But they should, too. I am not even the
administrator. I am just the "one who knew how to put in a password protect"
- ha-ha, jokes on them there". But I have done this many times and it has
worked. I am puzzled why it would suddenly not want to let anyone in except
myself. I was even careful NOT to use my Vista machine, but to use my older
2003 machine, so that wouldn't be a screwup, even though i haven't gotten any
problem like this from the crossover (different problems, but not this one).
 
G

Gord Dibben

"They" don't get asked for a password to open?

Just the message about 'administrator set password" and nothing else?

I'm not sure but maybe something to do with Windows permissions or group
policies.

Doesn't sound like an Excel-generated issue.


Gord
 
A

amir almousa

i want to attach file shoing how to highly protect an excel sheet .: But how can i atach this file ?...anyway this is my email for further help .sorry for my english i'm arabic man.



Kevin Smith wrote:

Hello,In the "ThisWorkbook" section in the VBE you can use this code to check
01-Sep-09

Hello

In the "ThisWorkbook" section in the VBE you can use this code to check th
computer ID and then unprotect the spreadsheet so that it can be edited

Private Sub Workbook_Open(
If Not Environ("ComputerName") = "YourComputerName" The
Application.Qui
End I
ActiveSheet.Unprotect Password:="YourPassword
End Su

then in the same section use ..

Private Sub Workbook_BeforeClose(Cancel As Boolean
ActiveSheet.Protect Password:="YourPassword", DrawingObjects:=False
Contents:=True, Scenarios:=Tru
End Su

this will password protect your spreadsheet again when you close it
-
Kevin Smith :eek:

:

Previous Posts In This Thread:

Protect Excel Worksheet to be opened on one PC only
Hello

I am looking for a solution to protect an Excel document to be opened on on
computer only. On other computers, the Excel document should show a messag
like "This document cannot be opened on this computer" or just fail to open

The idea is to protect intellectual property in that document (and t
prohibit its usage, so a simple cell protection would not be enough)

Third party solutions would be OK too

Any answers would be highly appreciated

Thank you
Fabian

Hello,In the "ThisWorkbook" section in the VBE you can use this code to check
Hello

In the "ThisWorkbook" section in the VBE you can use this code to check th
computer ID and then unprotect the spreadsheet so that it can be edited

Private Sub Workbook_Open(
If Not Environ("ComputerName") = "YourComputerName" The
Application.Qui
End I
ActiveSheet.Unprotect Password:="YourPassword
End Su

then in the same section use ..

Private Sub Workbook_BeforeClose(Cancel As Boolean
ActiveSheet.Protect Password:="YourPassword", DrawingObjects:=False
Contents:=True, Scenarios:=Tru
End Su

this will password protect your spreadsheet again when you close it
-
Kevin Smith :eek:

:

Hi Kevin,thanks for your answer!
Hi Kevin

thanks for your answer

But would not it be possible for the user to not execute macros and to ope
the workbook then? OK, it would be protected, but it seems not completel
safe to me

Fabia

:

You are correct that they can bypass the code but if you password protect the
You are correct that they can bypass the code but if you password protect th
information then all thay will be able to do is view the data rather tha
edit it. on the PC that you specify you will not need to unprotect an
protect the date because that is handled in the code

it is something that i do with excel and access, i check the ComputerNam
and User Name. if it is not me then it protects the data and if it is me the
it allows me full access
-
Kevin Smith :eek:

:

Excel internal security is very weak and passwords can be easily cracked.
Excel internal security is very weak and passwords can be easily cracked. N
matter how hard you try; any user with the intend of opening the files ca
easily google and get a password cracker. So suggest not to use excel t
store such data..

If this post helps click Ye
--------------
Jacob Skari

:

ok, thanks for the the code snippet.
ok, thanks for the the code snippet. It could be a solution of last-resort
problem is that the user needs to allow the Macros (we are dealing with en
users here). And I believe that the built-in Excel protection is not totall
secure (anyone has details about this)

But anyways, thanks for your help!

:

No problems.
No problems. Just be careful though because like Jacob said excel is weak in
security and no matter what you do to protect the information someone will be
able to get in if they wanted to.
--
Kevin Smith :eek:)


:

Another option would be Private Sub Workbook_BeforeClose(Cancel As
Another option would be

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet2").Visible = xlVeryHidden
End Sub

The Very Hidden statement means that the sheet can not be displayed through
the normal options "Format-Sheets-Unhide" It can only be displayed again
through code. i.e.

Private Sub Workbook_Open()
Sheets("Sheet2").Visible = True
End Sub

If you hide the sheets on the workbook close then even if people Bypass the
code then they still will not be able to view the sheet with information on
it.
--
Kevin Smith :eek:)


:

I have the opposite problem.
I have the opposite problem. I set a password for our Excel worksheets so
only the three of us who use it could get in, and only I can . . . it does not
even ask them for the password . . . just says "administrator set password".
Any idea what have I done wrong? We have 2003 and I used Tools, General
Options to set the password.
Thanks for any ideas.

:

You did not set a pasword for the sheets.
You did not set a pasword for the sheets.

Where you set the password was under File>Save As>Tools>General Options
password to open the file(workbook)?

You do not get a password request when you open the file?


Gord Dibben MS Excel MVP

Gord, That is exactly what I did.
Gord, That is exactly what I did. I get the password prompt when I want to
open a file, but no one else does. But they should, too. I am not even the
administrator. I am just the "one who knew how to put in a password protect"
- ha-ha, jokes on them there". But I have done this many times and it has
worked. I am puzzled why it would suddenly not want to let anyone in except
myself. I was even careful NOT to use my Vista machine, but to use my older
2003 machine, so that would not be a screwup, even though i have not gotten any
problem like this from the crossover (different problems, but not this one).


:

"They" don't get asked for a password to open?
"They" do not get asked for a password to open?

Just the message about 'administrator set password" and nothing else?

I am not sure but maybe something to do with Windows permissions or group
policies.

Doesn't sound like an Excel-generated issue.


Gord


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Control?s Default Style or Template by Extending the WPF Designer in Visual Studio 2010
http://www.eggheadcafe.com/tutorial...g-the-wpf-designer-in-visual-studio-2010.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top