ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Locking A sheet (https://www.excelbanter.com/excel-discussion-misc-queries/125573-locking-sheet.html)

Nigel

Locking A sheet
 
I am using a Custom Button to lock/unlock a sheet

If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect

With Application.CommandBars.ActionControl
.Caption = "Protect Sheet"
End With
Exit Sub
End If

With Application.CommandBars.ActionControl
.Caption = "Un Protect Sheet"
End With
ActiveSheet.Protect

if the sheet is unlocked the code will work and change the button text but
when I go to relock the sheet the line of code to change the caption to
unlock sheet errors out with

Object Variable or With block variable not set

why does it work outsied the if statement and not inside

thanks


All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com