Excel VB Code Adjust for Worksheet Protect

Escanaba
Escanaba used Ask the Experts™
on
Hello,

Please review the code in the attached spreadsheet.  I am not experienced in VB code and hoping someone can assist.  When this code runs it creates new workbooks based on data in column C.  Each new workbook is password protected and the worksheets are also protected.  I need the code to be updated so for each new workbook the individual worksheets are locked but with no password on the sheet so the end-user can easily unlock for editing.  

Greatly appreciate any assistance.
EE-Sample.xlsm
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
try this, see attached

Sub CreateNewWorkbooks()
Dim swb As Workbook, wb As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim lr As Long, i As Long
Dim FilePath As String, FileName As String
Dim x, dict, it

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set swb = ThisWorkbook
Set ws1 = swb.Sheets("Planning Worksheet")
Set ws2 = swb.Sheets("Instructions")
Set ws3 = swb.Sheets("2017 Band")

FilePath = "S:"

ws1.AutoFilterMode = False
lr = ws1.Cells(Rows.Count, 3).End(xlUp).Row

x = ws1.Range("C14:C" & lr)
Set dict = CreateObject("Scripting.Dictionary")

For i = 1 To UBound(x, 1)
    dict.Item(x(i, 1)) = ""
Next i

For Each it In dict.keys
    FileName = it & ".xlsx"
    With ws1.Rows(13)
        .AutoFilter field:=3, Criteria1:=it
        Set wb = Workbooks.Add
        ws1.Range("A1:AN" & lr).SpecialCells(xlCellTypeVisible).Copy wb.Sheets(1).Range("A1")
        wb.Sheets(1).Name = ws1.Name
        
        
         With wb.Sheets(1)
            .UsedRange.ColumnWidth = 15
            .Cells.Locked = False
            .Range("B:C,F:I,O:P,T:V,X:X,AE:AE,AJ:AK").Select
            .Range("F1").Activate
            Selection.Locked = True
            .Range("B:C,F:I,O:P,T:V,X:X,AE:AE,AJ:AK").EntireColumn.Hidden = True
            
            
        End With
        ws2.Copy after:=wb.Sheets(Sheets.Count)
        ws3.Copy after:=wb.Sheets(Sheets.Count)
        
            Sheets("Planning Worksheet").Select
            Range("L14").Select
        
        Application.DisplayAlerts = False
        
        
        wb.Protect Structure:=True, Windows:=False, Password:=""
        wb.Sheets(1).Protect "", True, True
        wb.SaveAs FilePath & FileName, FileFormat:=51, ReadOnlyRecommended:=False, CreateBackup:=False
        wb.Close
        Application.DisplayAlerts = True
        Set wb = Nothing
        Application.CutCopyMode = 0
    End With
Next it
ws1.AutoFilterMode = False
Application.ScreenUpdating = True
Application.CutCopyMode = 0
MsgBox dict.Count & " Workbooks have been created and saved in the folder " & FilePath & "!", vbInformation
End Sub

Open in new window

EE-Sample.xlsm
EscanabaManager - HR Analytics

Author

Commented:
We're close.  I still need the original workbook locked with the password prompt but each individual worksheet would be locked with no password.  So the worksheet part is working based on your change but I've lost the workbook lock and prompt.
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
do you mean , the password to open the workbook?
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Microsoft Excel Expert
Top Expert 2014
Commented:
ok then , please find attached.
EE-Sample.xlsm
EscanabaManager - HR Analytics

Author

Commented:
Sorry - that was confusing.  The workbooks should be locked with the password prompt as it shows in the sample file but I need each individual sheet locked with no password.  This would allow the end-user to go to the 'Review' tab on ribbon and unprotect if necessary.
EscanabaManager - HR Analytics

Author

Commented:
Just needed to remove the password prompt for sheet but after that it works like a charm.  Thanks for the assist!
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
You're welcome I'm glad I was able to help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial