Results 1 to 5 of 5

Thread: Protecting Multiple Workbooks

  1. #1

    Protecting Multiple Workbooks



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Is there an easy way to protect multiple workbooks (over 500) without opening each one and selecting the option?

    Same question for whether I could protect the worksheets within each workbook.

    Thanks,
    Pam

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,251
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Protecting the worksheets in each workbook, yes. Protecting each workbook, no. Each would need to be opened and saved, setting the password in the process.

    To protect each worksheet in an open workbook though... that's actually pretty easy. What version of Excel are you using?
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training) or with my book M is for Data Monkey!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,251
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    At least, I should probably clarify that...

    Yes, either can actually be done. There's more scripting involved with opening each workbook in a folder, but it is possible.

    Are all the workbooks in one folder, or a couple of folders?
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training) or with my book M is for Data Monkey!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  4. #4
    There will eventually be 1000+ files (that we are creating via a script, and prepopulating some of the data). 2 of 10 sheets are prepopulated so the base file that we are using needs these to be unprotected (and the workbook). The 1000 files will be in ~12 folders (created into these folders via the same script that is prepopulating the data).

    Pam

  5. #5
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,251
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    If you're creating the files via a script, I can't see any reason why you couldn't script the protection for both sheets and workbook names. In order to prepopulate the files with data, you have to have it open, so you could apply protection then.

    Just as an interesting aside, you can also protect all worksheets so that users can't access the data, but macros can. The only rub is that the setting to do that is not persistent so needs to be set each time the workbook is opened. (Which can also be scripted.)

    For reference, the following code, saved to your personal workbook, would allow you to protect all worksheets in the active workbook:

    Code:
    Public Sub ProtectAllSheets()
        Dim pWrd As Variant
        Dim ws As Worksheet
        
        'Ask the user for the password
        pWrd = CStr(InputBox("Please enter the password to use", "Enter password"))
        
        'Check what to do if password is blank or omitted
        If Len(pWrd) = 0 Then
            Select Case MsgBox("No password provided.  Protect sheets with no password?", _
                vbYesNoCancel, "I'm confused")
                Case Is = vbNo, vbCancel
                    Exit Sub
                Case Else
                    'User wants blank password
            End Select
        End If
        
        'Protect the worksheets
        For Each ws In ActiveWorkbook.Worksheets
            ws.Protect Password:=pWrd
        Next wsEnd Sub
    To do the workbook open one though... I'd be curious to learn a little more about the coding that you're currently doing.
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training) or with my book M is for Data Monkey!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

Posting Permissions

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