Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro for unprotecting a workbook and unhiding a sheet

Status
Not open for further replies.

Romary

IS-IT--Management
Mar 12, 2003
9
US
I need a macro that will unprotect my workbook and then unhide a sheet so that I can manipuate some cells on the hidden sheet. I then need to rehide the sheet and protect the workbook.

How can this be done?
 
The macro recorder doesn't record the unprotection of the workbook.
 
Hi,

To update a protected cell or range of cells in a worksheet, wrap the procedure with the following code:

ActiveSheet.Unprotect (“Password”)
' The rest of your code goes here
ActiveSheet.Protect Pasword:=“Password”

Where the string enclosed in quotes as “Password” contains the actual password.

To hide a specific worksheet, you could use:

Sub Hide_WS1()
Worksheets(MySheet).Visible = False
End Sub

To unhide a specific worksheet, you could use:

Sub UnHide_WS()
Worksheets(MySheet).Visible = True
End Sub

where "MySheet" is the sheet name.

However, if you know which cells need to be changed, you should be able to do that without unhiding the worksheet.

Cheers

 
Thank you for the suggestion but this unprotects a sheet. I need to unprotect the workbook. Tools-Protection-Unprotect Workbook.
 
What about this ?
ActiveWorkbook.Unprotect(“Password”)


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Oh sorry about that Romary, I miss read it as well as unprotect worksheet.

Frank
 
Sorry,

Mis-read the post. To open & unprotect the workbook you could use:

Workbooks.Open Filename:="C:\My Documents\My File.xls", Password:="My Password"

After you've finished updating & saving, you won't need to re-protect the workbook unless you want to change the password.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top