+ Reply to Thread
Results 1 to 7 of 7

Please help!!! Using code to password-protect and unprotect...

  1. #1
    Hawk
    Guest

    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. #2
    KL
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    STEVE BELL
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




  4. #4
    Hawk
    Guest

    Re: Please help!!! Using code to password-protect and unprotect...

    It worked!! Thanks KL...


  5. #5
    STEVE BELL
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > It worked!! Thanks KL...
    >




  6. #6
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > It worked!! Thanks KL...
    > >

    >
    >




  7. #7
    STEVE BELL
    Guest

    Re: Please help!!! Using code to password-protect and unprotect...

    My miss-read...

    --
    steveB

    Remove "AYN" from email to respond
    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > He said thanks to **KL** -- maybe it sounded like Steve Bell <g>
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "STEVE BELL" <[email protected]> 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" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > It worked!! Thanks KL...
    >> >

    >>
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1