• Protecting all sheets (Excel XP)

    Author
    Topic
    #395258

    I have recorded a macro to protect a single sheet : ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

    What code do I add to get it to protect all sheets in the workbook ?
    Something like:

    For each sheet in the workbook
    Protect using the current options for each sheet
    Next sheet

    Viewing 1 reply thread
    Author
    Replies
    • #731512

      Something like the following (untested):

      Dim oSheet as Worksheet
          For Each oSheet in Worksheets
              oSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
          Next oSheet
      
      • #731516

        Thanks Legare, works like a charm.

        It saves a lot of time. I have about 20 sheets in the workbook, and to make changes, it takes forever to unprotect then protect each sheet individually.
        I added a second macro to unprotect (oSheet.Unprotect), and now I can turn off my coputer and go to bed with a smile on my face…

        Good work.

      • #731517

        Thanks Legare, works like a charm.

        It saves a lot of time. I have about 20 sheets in the workbook, and to make changes, it takes forever to unprotect then protect each sheet individually.
        I added a second macro to unprotect (oSheet.Unprotect), and now I can turn off my coputer and go to bed with a smile on my face…

        Good work.

    • #731513

      Something like the following (untested):

      Dim oSheet as Worksheet
          For Each oSheet in Worksheets
              oSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
          Next oSheet
      
    Viewing 1 reply thread
    Reply To: Protecting all sheets (Excel XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: