Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Please help!!! Using code to password-protect and unprotect...

With help from this group, I am using the following code to hide empty
columns in my spreadsheet. It works when my sheet is not protected,
however, when I deploy this sheet for use by others it will need to be
password-protected. What can I add to the code to unprotect the sheet
prior to hiding the columns and then re-protect the sheet after the
columns have been hidden? Will my password-protection be preserved?
Please help...

Sub Hide_EmptyColumns()
'To hide columns with no data in rows 10:82


Application.ScreenUpdating = False
With Sheets("Box")
Dim col As Range
For Each col In .Range("C10:AF82").Columns
col.EntireColumn.Hidden = _
Application.Sum(col) = 0

Next
End With
Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Please help!!! Using code to password-protect and unprotect...

Hi Hawk,

Try this:

Sub Hide_EmptyColumns()
'To hide columns with no data in rows 10:82
Application.ScreenUpdating = False
Dim col As Range, Pass As String
Pass = "password"
With Sheets("Box")
.Protect Pass
For Each col In .Range("C10:AF82").Columns
col.EntireColumn.Hidden = _
Application.Sum(col) = 0
Next
.Unprotect Pass
End With
Application.ScreenUpdating = True
End Sub


Regards,
KL


"Hawk" wrote in message
ups.com...
With help from this group, I am using the following code to hide empty
columns in my spreadsheet. It works when my sheet is not protected,
however, when I deploy this sheet for use by others it will need to be
password-protected. What can I add to the code to unprotect the sheet
prior to hiding the columns and then re-protect the sheet after the
columns have been hidden? Will my password-protection be preserved?
Please help...

Sub Hide_EmptyColumns()
'To hide columns with no data in rows 10:82


Application.ScreenUpdating = False
With Sheets("Box")
Dim col As Range
For Each col In .Range("C10:AF82").Columns
col.EntireColumn.Hidden = _
Application.Sum(col) = 0

Next
End With
Application.ScreenUpdating = True
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Please help!!! Using code to password-protect and unprotect...

It worked!! Thanks KL...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Please help!!! Using code to password-protect and unprotect...

Glad you like it...

This code has been very useful for me...

Thanks go to Greg Wilson...

--
steveB

Remove "AYN" from email to respond
"Hawk" wrote in message
ups.com...
It worked!! Thanks KL...



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Please help!!! Using code to password-protect and unprotect...

He said thanks to **KL** -- maybe it sounded like Steve Bell <g

--
Regards,
Tom Ogilvy

"STEVE BELL" wrote in message
news:%aCze.648$Zy6.604@trnddc04...
Glad you like it...

This code has been very useful for me...

Thanks go to Greg Wilson...

--
steveB

Remove "AYN" from email to respond
"Hawk" wrote in message
ups.com...
It worked!! Thanks KL...







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Please help!!! Using code to password-protect and unprotect...

My miss-read...

--
steveB

Remove "AYN" from email to respond
"Tom Ogilvy" wrote in message
...
He said thanks to **KL** -- maybe it sounded like Steve Bell <g

--
Regards,
Tom Ogilvy

"STEVE BELL" wrote in message
news:%aCze.648$Zy6.604@trnddc04...
Glad you like it...

This code has been very useful for me...

Thanks go to Greg Wilson...

--
steveB

Remove "AYN" from email to respond
"Hawk" wrote in message
ups.com...
It worked!! Thanks KL...







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Please help!!! Using code to password-protect and unprotect...

Here's something from Greg Wilson.

It does 2 things
1. The user can only select unprotected cells
2. This part
WS.Protect 'Password:="wxyz", UserInterfaceOnly:=True
allows code to run on a protected sheet

see if this helps...


Select UnProtected Cells ONLY

This will prevent users from clicking on protected cells on all

worksheets. Therefore, the warning message will not appear. The code

must be enterred in the ThisWorkbook module.



Note that the EnableSelection property must be reset each time the

workbook is opened as it defaults to xlNoRestrictions. The worksheet(s)

must first be unprotected to set the EnableSelection property and then

must be protected for it to take effect.



Private Sub Workbook_Open()

Dim WS As Worksheet

For Each WS In ThisWorkbook.Worksheets

WS.Unprotect 'Password:="wxyz"

WS.EnableSelection = xlUnlockedCells

WS.Protect 'Password:="wxyz", UserInterfaceOnly:=True

Next

End Sub



Regards,

Greg Wilson 5/3/03


--
steveB

Remove "AYN" from email to respond
"Hawk" wrote in message
ups.com...
With help from this group, I am using the following code to hide empty
columns in my spreadsheet. It works when my sheet is not protected,
however, when I deploy this sheet for use by others it will need to be
password-protected. What can I add to the code to unprotect the sheet
prior to hiding the columns and then re-protect the sheet after the
columns have been hidden? Will my password-protection be preserved?
Please help...

Sub Hide_EmptyColumns()
'To hide columns with no data in rows 10:82


Application.ScreenUpdating = False
With Sheets("Box")
Dim col As Range
For Each col In .Range("C10:AF82").Columns
col.EntireColumn.Hidden = _
Application.Sum(col) = 0

Next
End With
Application.ScreenUpdating = True
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
Code to protect/unprotect a sheet using a macro with password FredH Excel Discussion (Misc queries) 5 October 23rd 07 04:49 PM
Password - Protect, UnProtect MrAlMackay Excel Programming 5 January 19th 05 07:23 PM
Protect/unprotect sheet with password with VBA? dragontale[_7_] Excel Programming 1 April 19th 04 09:29 PM
VBA code - protect and unprotect a sheet Jeff Excel Programming 2 December 2nd 03 11:44 PM


All times are GMT +1. The time now is 06:56 PM.

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

About Us

"It's about Microsoft Excel"