ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro (https://www.excelbanter.com/excel-worksheet-functions/8712-macro.html)

John

Macro
 
Can you unprotect a sheet within a Macro?

Paul B

John, yes something like this


Sub test()

ActiveSheet.Unprotect password:="123" 'change password here

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


"John" wrote in message
...
Can you unprotect a sheet within a Macro?




Peo Sjoblom

Yes

Sub UnProtectSheet()
PWD = "password"
Worksheets("sheet1").Unprotect Password:=PWD
End Sub



Regards,

Peo Sjoblom

"John" wrote:

Can you unprotect a sheet within a Macro?


John

This unfortunately did not work. I am using two worksheets if that changes
anything.
I have a space for a tax ID number, but in some cases you might use and
Federal Tax ID number (FEIN) If i have the protection off, it changes the
cell format, then takes that number and puts it in another cell in a
different worksheet and changes the cell format again to FEIN, then takes you
back to the original worksheet. However when you put the protection on, it
wont work.

"Peo Sjoblom" wrote:

Yes

Sub UnProtectSheet()
PWD = "password"
Worksheets("sheet1").Unprotect Password:=PWD
End Sub



Regards,

Peo Sjoblom

"John" wrote:

Can you unprotect a sheet within a Macro?



All times are GMT +1. The time now is 12:53 AM.

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