Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
Below is the macro used and it did not password protect every sheet in the
workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
I don't know - but see if this does better:
Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet, sh as Worksheet set sh = Activesheet Application.ScreenUpdating = False For Each sht In Worksheets hval = sht.Visible sht.visible = xlSheetVisible sht.Select sht.Protect pword sht.Visible = hval Next sht sh.Select Application.ScreenUpdating = True End Sub -- regards, Tom Ogilvy "Brad" wrote: Below is the macro used and it did not password protect every sheet in the workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
Out on a limb here but are they all worksheets or are some of them chart
sheets or macro sheets... If so then you want to go through the Sheets collection and not the worksheets collection... -- HTH... Jim Thomlinson "Brad" wrote: Below is the macro used and it did not password protect every sheet in the workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
What should the hval be set as -- constant?
"Tom Ogilvy" wrote: I don't know - but see if this does better: Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet, sh as Worksheet set sh = Activesheet Application.ScreenUpdating = False For Each sht In Worksheets hval = sht.Visible sht.visible = xlSheetVisible sht.Select sht.Protect pword sht.Visible = hval Next sht sh.Select Application.ScreenUpdating = True End Sub -- regards, Tom Ogilvy "Brad" wrote: Below is the macro used and it did not password protect every sheet in the workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
All of them are "regular" worksheets - no chart sheets or macro sheets.
"Jim Thomlinson" wrote: Out on a limb here but are they all worksheets or are some of them chart sheets or macro sheets... If so then you want to go through the Sheets collection and not the worksheets collection... -- HTH... Jim Thomlinson "Brad" wrote: Below is the macro used and it did not password protect every sheet in the workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
dim hval as long
Brad wrote: What should the hval be set as -- constant? "Tom Ogilvy" wrote: I don't know - but see if this does better: Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet, sh as Worksheet set sh = Activesheet Application.ScreenUpdating = False For Each sht In Worksheets hval = sht.Visible sht.visible = xlSheetVisible sht.Select sht.Protect pword sht.Visible = hval Next sht sh.Select Application.ScreenUpdating = True End Sub -- regards, Tom Ogilvy "Brad" wrote: Below is the macro used and it did not password protect every sheet in the workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub -- Dave Peterson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
Figured out what the problem was - the sheets were already protected but not
password protected. When I unprotected the sheets, the original macro worked fine. What should I have done differently to make the macro work whether the sheet was protected or not?? "Brad" wrote: Below is the macro used and it did not password protect every sheet in the workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro not protecting every sheet
Check if it is already protected before you try to protect it.
-- Regards, Tom Ogilvy "Brad" wrote in message ... Figured out what the problem was - the sheets were already protected but not password protected. When I unprotected the sheets, the original macro worked fine. What should I have done differently to make the macro work whether the sheet was protected or not?? "Brad" wrote: Below is the macro used and it did not password protect every sheet in the workbook. At the time that the macro was ran there were some sheets that we hidded - some were very hidden. But that shouldn't make a difference should it? I have about 30 sheets in the workbook. Sub lockdown() Const pword As String = "XXXX" Dim sht As Worksheet For Each sht In Worksheets sht.Protect pword Next sht End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
protecting formulas without protecting sheet so grouping still wor | Excel Discussion (Misc queries) | |||
protecting a sheet | Excel Discussion (Misc queries) | |||
Macro for protecting sheet | Excel Discussion (Misc queries) | |||
Protecting sheet that has macro | Excel Worksheet Functions | |||
macro for Protecting a Sheet | Excel Discussion (Misc queries) |