Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button
I would like to be able to protect a sheet if it currently is not protected
and unprotect the sheet if it is protected. I know how to record a macro and I think I can figure out how to get it to work on a button, but I would need two buttons. I was wondering if it was possible to have one button that would check the status and reverse it. Also, if it is possible how would I get the name on the button to change? Any help will be greatly appreciated. I don't know allot about programming so talk real slow. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button
In XL show the Control Toolbox (Tools - Customize - Toolbars - Check
Control Toolbox). Drag a Button off the toolbar and place it on the sheet. Right click the sheet tab and select view code. Paste the following code... Private Sub CommandButton1_Click() With ActiveSheet If .ProtectContents = True Then .Unprotect CommandButton1.Caption = "Unprotected" Else .Protect CommandButton1.Caption = "Protected" End If End With End Sub -- HTH... Jim Thomlinson "Jordan" wrote: I would like to be able to protect a sheet if it currently is not protected and unprotect the sheet if it is protected. I know how to record a macro and I think I can figure out how to get it to work on a button, but I would need two buttons. I was wondering if it was possible to have one button that would check the status and reverse it. Also, if it is possible how would I get the name on the button to change? Any help will be greatly appreciated. I don't know allot about programming so talk real slow. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button
Jim, Thank you so much. It works perfect and unless the folks at my work are
perusing the discussion group, they are going to think I really know what I'm doing. Thanks again. "Jim Thomlinson" wrote: In XL show the Control Toolbox (Tools - Customize - Toolbars - Check Control Toolbox). Drag a Button off the toolbar and place it on the sheet. Right click the sheet tab and select view code. Paste the following code... Private Sub CommandButton1_Click() With ActiveSheet If .ProtectContents = True Then .Unprotect CommandButton1.Caption = "Unprotected" Else .Protect CommandButton1.Caption = "Protected" End If End With End Sub -- HTH... Jim Thomlinson "Jordan" wrote: I would like to be able to protect a sheet if it currently is not protected and unprotect the sheet if it is protected. I know how to record a macro and I think I can figure out how to get it to work on a button, but I would need two buttons. I was wondering if it was possible to have one button that would check the status and reverse it. Also, if it is possible how would I get the name on the button to change? Any help will be greatly appreciated. I don't know allot about programming so talk real slow. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
command button add another command | Excel Discussion (Misc queries) | |||
VB's Command Button vs Form's Command Button | Excel Programming | |||
Command Button vs Form Button | Excel Programming | |||
Command Button vs Control Button | Excel Programming | |||
Command Button vs Form Button | Excel Programming |