![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 18
|
a button so that when it is [ress it will protect the sheet, and press again to unprotect the sheet?
also is it possible so that after the sheet is protected the button text will say "click unprotect sheet" and when it is pressed again it will say " click to protect sheet" |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Hi,
If you place the commandbutton on your sheet and change it's caption to Click to Protect Sheet. Then double click the button and use this code:- Code:
Private Sub CommandButton1_Click()
If Me.CommandButton1.Caption = "Click to protect sheet" Then
Me.Protect "passwordIfyouwant"
Me.CommandButton1.Caption = "Click to unprotect sheet"
Else
Me.Unprotect "passwordIfyouwant"
Me.CommandButton1.Caption = "Click to protect sheet"
End If
End Sub
D [ This Message was edited by: dk on 2002-02-25 07:18 ] [ This Message was edited by: dk on 2002-02-25 07:19 ] |
|
|
|
|
|
#3 |
|
Guest
Posts: n/a
|
When I try this I get runtime error 1004
How can I fix it? |
|
|
|
#4 |
|
New Member
Join Date: Feb 2002
Posts: 18
|
didn't work, it says "invaild use of Me keyword" ;/
|
|
|
|
|
|
#5 |
|
New Member
Join Date: Feb 2002
Posts: 18
|
*bump*
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Are you using the command button from View, Toolbars, Control Toolbox? If you place that button on the sheet and make sure you're in Design mode (the blue set square icon on the Control Toolbox is pressed in). Now double click the button. It will take you to the code module of the button's parent - in this case the sheet code module. Put the code there - not in a standard module.
Any more problems, let me know, Regards, D |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|