#1   Report Post  
Nick
 
Posts: n/a
Default Password Protecting

I am trying to write some code so when a button is pressed a password message
comes up and needs to be entered for accessing the information.

Any ideas people. Would be very grateful as been trying this for a while now
  #2   Report Post  
Paul B
 
Posts: n/a
Default

Nick, something like this, you will need lock the VBA project so you can't
see the password in it


Sub PassWord_To_Run()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then

'your code here

Else
MsgBox ("Access Denied")
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
I am trying to write some code so when a button is pressed a password

message
comes up and needs to be entered for accessing the information.

Any ideas people. Would be very grateful as been trying this for a while

now


  #3   Report Post  
Nick
 
Posts: n/a
Default

Cheers mate, thats fantastic. Just one other question. Can you do the same so
if the sheet2 is clicked (at bottom left of excel sheet) a password box
appears. I want to set my program up so access to sheet2 is password
protected so no-one can view its contents.

"Paul B" wrote:

Nick, something like this, you will need lock the VBA project so you can't
see the password in it


Sub PassWord_To_Run()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then

'your code here

Else
MsgBox ("Access Denied")
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
I am trying to write some code so when a button is pressed a password

message
comes up and needs to be entered for accessing the information.

Any ideas people. Would be very grateful as been trying this for a while

now



  #4   Report Post  
Paul B
 
Posts: n/a
Default

Nick, here is some code, to put in this macro right click on the worksheet
tab and view code, in the
window that opens paste this code, press Alt and Q to close this window and
go back to your workbook.

Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="123"
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < "123" Then
MsgBox "Password Incorrect "
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:="123"
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub


Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub


Be aware that sheet passwords are very easy to break and all somebody would
have to do is open the workbook with macros disabled unprotect the sheet and
then unhide the columns to see your data, this will keep out some people but
if somebody wants to see your data in Excel they will find a way, Excel is
not a secure platform.
You will also need to protect the VBA project so people can't see the
password from there.

To protect the VBA project, from your workbook right-click the workbook's
icon and pick View Code. This icon is to the left of the "File" menu this
will open the VBA editor, in the left hand window right click on your
workbook name and select VBA project properties, protection, check lock
project for viewing and set a password. Press Alt and Q to close this window
and go back to your workbook and save and close the file. Be aware that this
password can be broken by third party software




--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
Cheers mate, thats fantastic. Just one other question. Can you do the same

so
if the sheet2 is clicked (at bottom left of excel sheet) a password box
appears. I want to set my program up so access to sheet2 is password
protected so no-one can view its contents.

"Paul B" wrote:

Nick, something like this, you will need lock the VBA project so you

can't
see the password in it


Sub PassWord_To_Run()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then

'your code here

Else
MsgBox ("Access Denied")
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
I am trying to write some code so when a button is pressed a password

message
comes up and needs to be entered for accessing the information.

Any ideas people. Would be very grateful as been trying this for a

while
now





  #5   Report Post  
Nick
 
Posts: n/a
Default

Cheers mate that works perfectly. Is there actually any way of getting the
password box to display without enntering the sheet. i.e when Sheet2 is
presses the pass word box is displayed before the sheet can be entered.

Thanks agin mate

"Paul B" wrote:

Nick, here is some code, to put in this macro right click on the worksheet
tab and view code, in the
window that opens paste this code, press Alt and Q to close this window and
go back to your workbook.

Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="123"
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < "123" Then
MsgBox "Password Incorrect "
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:="123"
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub


Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub


Be aware that sheet passwords are very easy to break and all somebody would
have to do is open the workbook with macros disabled unprotect the sheet and
then unhide the columns to see your data, this will keep out some people but
if somebody wants to see your data in Excel they will find a way, Excel is
not a secure platform.
You will also need to protect the VBA project so people can't see the
password from there.

To protect the VBA project, from your workbook right-click the workbook's
icon and pick View Code. This icon is to the left of the "File" menu this
will open the VBA editor, in the left hand window right click on your
workbook name and select VBA project properties, protection, check lock
project for viewing and set a password. Press Alt and Q to close this window
and go back to your workbook and save and close the file. Be aware that this
password can be broken by third party software




--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
Cheers mate, thats fantastic. Just one other question. Can you do the same

so
if the sheet2 is clicked (at bottom left of excel sheet) a password box
appears. I want to set my program up so access to sheet2 is password
protected so no-one can view its contents.

"Paul B" wrote:

Nick, something like this, you will need lock the VBA project so you

can't
see the password in it


Sub PassWord_To_Run()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then

'your code here

Else
MsgBox ("Access Denied")
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
I am trying to write some code so when a button is pressed a password
message
comes up and needs to be entered for accessing the information.

Any ideas people. Would be very grateful as been trying this for a

while
now








  #6   Report Post  
Paul B
 
Posts: n/a
Default

Nick, then how about this, it will hide sheet 2 using xl very hidden, you
want see it listed in the unhide menu so most people want know its there.
You will also need to protect the VBA project like before so the password
can't be seen or the sheet made visible from there. When you want to view
the sheet run the unhide_me macro.


Put this in the sheet code

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Visible = xlSheetVeryHidden
On Error GoTo 0
End Sub


And this in a regular module

Sub unhide_me()
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required To Run This Macro")
If MyStr1 = MyStr2 Then
Sheet2.Visible = xlSheetVisible
Sheet2.Select
Else
MsgBox ("Access Denied")
End If
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
Cheers mate that works perfectly. Is there actually any way of getting the
password box to display without enntering the sheet. i.e when Sheet2 is
presses the pass word box is displayed before the sheet can be entered.

Thanks agin mate

"Paul B" wrote:

Nick, here is some code, to put in this macro right click on the

worksheet
tab and view code, in the
window that opens paste this code, press Alt and Q to close this window

and
go back to your workbook.

Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="123"
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < "123" Then
MsgBox "Password Incorrect "
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:="123"
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub


Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub


Be aware that sheet passwords are very easy to break and all somebody

would
have to do is open the workbook with macros disabled unprotect the sheet

and
then unhide the columns to see your data, this will keep out some people

but
if somebody wants to see your data in Excel they will find a way, Excel

is
not a secure platform.
You will also need to protect the VBA project so people can't see the
password from there.

To protect the VBA project, from your workbook right-click the

workbook's
icon and pick View Code. This icon is to the left of the "File" menu

this
will open the VBA editor, in the left hand window right click on your
workbook name and select VBA project properties, protection, check lock
project for viewing and set a password. Press Alt and Q to close this

window
and go back to your workbook and save and close the file. Be aware that

this
password can be broken by third party software




--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
Cheers mate, thats fantastic. Just one other question. Can you do the

same
so
if the sheet2 is clicked (at bottom left of excel sheet) a password

box
appears. I want to set my program up so access to sheet2 is password
protected so no-one can view its contents.

"Paul B" wrote:

Nick, something like this, you will need lock the VBA project so you

can't
see the password in it


Sub PassWord_To_Run()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then

'your code here

Else
MsgBox ("Access Denied")
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit

from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
I am trying to write some code so when a button is pressed a

password
message
comes up and needs to be entered for accessing the information.

Any ideas people. Would be very grateful as been trying this for a

while
now








  #7   Report Post  
Nick
 
Posts: n/a
Default

Thanks alot mate. I actually sorted the problem by writing
sheets("sheet1").select at the start of the macro. I will try your method as
well as see which works best for my application. Thanks for all the help i'm
very grateful.

Thanks again Paul

"Paul B" wrote:

Nick, then how about this, it will hide sheet 2 using xl very hidden, you
want see it listed in the unhide menu so most people want know its there.
You will also need to protect the VBA project like before so the password
can't be seen or the sheet made visible from there. When you want to view
the sheet run the unhide_me macro.


Put this in the sheet code

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Visible = xlSheetVeryHidden
On Error GoTo 0
End Sub


And this in a regular module

Sub unhide_me()
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required To Run This Macro")
If MyStr1 = MyStr2 Then
Sheet2.Visible = xlSheetVisible
Sheet2.Select
Else
MsgBox ("Access Denied")
End If
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
Cheers mate that works perfectly. Is there actually any way of getting the
password box to display without enntering the sheet. i.e when Sheet2 is
presses the pass word box is displayed before the sheet can be entered.

Thanks agin mate

"Paul B" wrote:

Nick, here is some code, to put in this macro right click on the

worksheet
tab and view code, in the
window that opens paste this code, press Alt and Q to close this window

and
go back to your workbook.

Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="123"
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < "123" Then
MsgBox "Password Incorrect "
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:="123"
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub


Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub


Be aware that sheet passwords are very easy to break and all somebody

would
have to do is open the workbook with macros disabled unprotect the sheet

and
then unhide the columns to see your data, this will keep out some people

but
if somebody wants to see your data in Excel they will find a way, Excel

is
not a secure platform.
You will also need to protect the VBA project so people can't see the
password from there.

To protect the VBA project, from your workbook right-click the

workbook's
icon and pick View Code. This icon is to the left of the "File" menu

this
will open the VBA editor, in the left hand window right click on your
workbook name and select VBA project properties, protection, check lock
project for viewing and set a password. Press Alt and Q to close this

window
and go back to your workbook and save and close the file. Be aware that

this
password can be broken by third party software




--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
Cheers mate, thats fantastic. Just one other question. Can you do the

same
so
if the sheet2 is clicked (at bottom left of excel sheet) a password

box
appears. I want to set my program up so access to sheet2 is password
protected so no-one can view its contents.

"Paul B" wrote:

Nick, something like this, you will need lock the VBA project so you
can't
see the password in it


Sub PassWord_To_Run()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("123") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then

'your code here

Else
MsgBox ("Access Denied")
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit

from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Nick" wrote in message
...
I am trying to write some code so when a button is pressed a

password
message
comes up and needs to be entered for accessing the information.

Any ideas people. Would be very grateful as been trying this for a
while
now









Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Data Keeps asking for Password Dominator Excel Discussion (Misc queries) 0 June 5th 05 11:25 PM
Password protecting certain worksheets in a file Mike Excel Discussion (Misc queries) 1 March 30th 05 03:53 AM
bypass password when update linking of password protected file Yan Excel Discussion (Misc queries) 1 February 7th 05 11:29 PM
How Delete Network Password Request-Worksheet in Website brsscreen Excel Worksheet Functions 0 December 14th 04 07:47 PM
Password cannot be removed twa14 Excel Discussion (Misc queries) 3 December 14th 04 11:27 AM


All times are GMT +1. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"