ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   applying worksbook protection via a Macro (https://www.excelbanter.com/excel-programming/385622-applying-worksbook-protection-via-macro.html)

David S

applying worksbook protection via a Macro
 
Can an one tell me how to record a macro that will un-password protect a
workbook then hide several worksheets then re-password protect the workbook?

Corey

applying worksbook protection via a Macro
 
Sub ProtectWkbandHideSheets()

ActiveWorkbook.Unprotect Password = "123"
Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Sheet3").Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWorkbook.Protect Password = "123"
End Sub

Change sheets and P/W to suit.

Corey....
"David S" <David wrote in message
...
Can an one tell me how to record a macro that will un-password protect a
workbook then hide several worksheets then re-password protect the workbook?



Gord Dibben

applying worksbook protection via a Macro
 
Here's one already built.

Sub hide_em()
ActiveWorkbook.Unprotect Password:="justme"
Worksheets(Array("sheet1", "Sheet3", _
"Sheet5")).Visible = False
ActiveWorkbook.Protect Password:="justme", Structu=True, Windows:=True
End Sub

If you were to record doing this your code would look like so..........

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 03-19-2007 by Gord Dibben
'
ActiveWorkbook.Unprotect
Sheets(Array("Sheet1", "Sheet3", "Sheet5")).Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWorkbook.Protect Structu=True, Windows:=True
End Sub


Notice that no password is recorded so you have to add it as the hide_em sub
does.


Gord Dibben MS Excel MVP

On Mon, 19 Mar 2007 13:36:10 -0700, David S <David
wrote:

Can an one tell me how to record a macro that will un-password protect a
workbook then hide several worksheets then re-password protect the workbook?




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

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