Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default 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
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
command button add another command Wanna Learn Excel Discussion (Misc queries) 5 December 7th 08 11:42 PM
VB's Command Button vs Form's Command Button Ronald Dodge Excel Programming 3 May 24th 06 02:23 PM
Command Button vs Form Button Bri[_3_] Excel Programming 2 February 3rd 06 08:18 AM
Command Button vs Control Button RGibson Excel Programming 1 October 14th 03 02:24 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 03:46 AM.

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

About Us

"It's about Microsoft Excel"