Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
protecting formulas without protecting sheet so grouping still wor JM Excel Discussion (Misc queries) 1 June 4th 09 06:42 AM
protecting a sheet des-sa[_2_] Excel Discussion (Misc queries) 3 January 15th 09 08:53 PM
Macro for protecting sheet JoeP Excel Discussion (Misc queries) 2 November 27th 07 12:05 AM
Protecting sheet that has macro ub Excel Worksheet Functions 5 October 6th 07 12:37 AM
macro for Protecting a Sheet cincode5 Excel Discussion (Misc queries) 5 July 20th 05 11:59 AM


All times are GMT +1. The time now is 03:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"