Hi, I have the following code and at line 200 the wrong workbook is having cells unprotected. How do I make the "final" workbook change and not the "Backup"? Having a brain fart today Thanks for the help!
Private Sub Mill_Reports_Final()
'declare varibales
Dim Wb As Workbook
Dim Ws As Worksheet
Dim strFile As String
'turn off the screen-updating to _
done everything in the backend
10 Application.ScreenUpdating = False
20 Application.DisplayAlerts = False
30 Sheet6.Visible = xlSheetVeryHidden
40 Sheet8.Visible = xlSheetVeryHidden
50 Sheet4.Shapes.Range(Array("Button 1")).Visible = msoFalse
'Selection.Delete
60 Set Wb = Workbooks.Open(Environ("USERPROFILE") & "\Documents\Mill Four Sheets_Backup_" & Sheet2.Range("B4").Value & ".xlsm")
70 strFile = Environ("USERPROFILE") & "\Documents\Mill Four Sheets_Final_" & Sheet2.Range("B4").Value & ".xlsm"
'Delete previous _Final file if exists
80 If Len(Dir(strFile)) Then Kill strFile
'Save the workbook after protecting
90 Wb.SaveCopyAs fileName:=strFile ', _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
'Password:="", WriteResPassword:="", _
'ReadOnlyRecommended:=False, CreateBackup:=False
'Wb.Close SaveChanges:=False 'just close it. No need to save it again
100 If Sheet1.Range("AG1").Value = "D" Then
110 Sheet8.Visible = xlSheetVisible
'Sheet4.Range("AA1").Value = ""
120 ElseIf Sheet1.Range("AG1").Value = "N" Then
130 Sheet6.Visible = xlSheetVisible
'Sheet4.Range("AA1").Value = ""
140 End If
150 Sheet4.Shapes.Range(Array("Button 1")).Visible = msoTrue
'open the workbook that you want to protect
160 Set Wb = Workbooks.Open(Environ("USERPROFILE") & "\Documents\Mill Four Sheets_Final_" & Sheet2.Range("B4").Value & ".xlsm")
170 For Each Ws In Wb.Worksheets
180 Ws.Cells.Locked = True
'Ws.Protect "Pword"
190 Next Ws
200 With Sheet1
210 .Unprotect "DjS"
220 .Range("L9:M15").Locked = False
230 .Range("N7:N17").Locked = False
240 .Range("N25:N28").Locked = False
250 .Protect "DjS"
260 End With
270 If ActiveWorkbook.Sheets("Sheet5").Visible = xlSheetVisible Then
280 With Sheet5
290 .Unprotect "DjS"
300 .Range("L9:M15").Locked = False
310 .Range("N7:N17").Locked = False
320 .Range("N25:N28").Locked = False
330 .Protect "DjS"
340 End With
350 End If
360 Application.EnableEvents = False
'Workbooks.Open (Environ("USERPROFILE") & "\Documents\Mill Four Sheets_Backup_" & Sheet2.Range("B4").Value & ".xlsm")
370 Wb.Close SaveChanges:=True
'turn on the screen-updating
380 Application.ScreenUpdating = True
390 Application.DisplayAlerts = True
400 Application.EnableEvents = True
End Sub
Bookmarks