Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: protection

  1. #1
    Board Regular
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    317
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have a series of sheet and graphs as sheet tabs in the same work book and i would like the macro code to protect and unprotect them all rather than just the worksheets. I use

    For Each ws in Sheets
    ws.protect Password:="password"
    Next ws
    End sub

    Thanks

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Sydney/Brisbane , Australia
    Posts
    542
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    this is code from NateO

    Sub alShts2()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    ws.Protect "password" 'change 'protect' to 'unprotect' to unprotect each sheet
    Next ws
    End Sub

  3. #3
    Board Regular
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    317
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    thanks a million for the advice

  4. #4
    Board Regular
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    317
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    that works for the worksheets but stops at the charts tabs.

    Is there soemthing missing?

  5. #5
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Qroozn, I appreciate the reference, seems like a long time ago that you and I were talking about flashing cells on the old board....

    To the matter at hand. Try:

    Code:
    Sub alShts3() 
    Dim ws As Worksheet 
    For Each ws In ThisWorkbook.Worksheets 
    ws.Protect "password" 'change 'protect' to 'unprotect' to unprotect each sheet 
    Next ws
    For Each ws In ThisWorkbook.Charts
    ws.Protect "password" 'change 'protect' to 'unprotect' to unprotect each sheet 
    Next ws
    End Sub
    Chart sheets and normal worksheets carry different properties, making them finicky. Have a good one y'all.


    _________________
    Cheers, NateO

    [ This Message was edited by: NateO on 2002-05-08 21:43 ]

  6. #6
    Board Regular
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    317
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    That creates a run time error 13

    type mismatch

  7. #7
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Bad variable. Try:

    Code:
    Sub Pro()
    Dim ws As Worksheet, ch As Chart
    For Each ws In ThisWorkbook.Worksheets
    ws.Protect "ps"
    Next ws
    For Each ch In ThisWorkbook.Charts
    ch.Protect "ps"
    Next ch
    End Sub
    Sorry 'bout the goof.

  8. #8
    Board Regular
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    317
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    excellent result thanks for the assistance u r a legend

  9. #9
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You're welcome. Have a good one!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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