TeeOpen_ProtectTee + TeeOpen_UnprotectTee

Protect or unprotect a workbook (already open) remotely from another workbook
This was imported from TeeMan system built back in 2017.
Expected to have settings named "TallyFile" and "TallyPass"
"TallyFile" is only needed if the call passed blank
"TallyPass" is the password to protect workbook and worksheets
It also hides the workbook window (needed in Excel 2013 and later)


Public

Tested

My Own Work

Sub TeeOpen_ProtectTee(Wb)
' Protect a Tee file
' Imported from TeeMan
' WB is workbook filename that is already open
WShe_spc = "TeeTallysheet" ' The special treatment sheet (very hidden)
If Wb = "" Then WB = SettingRead("TallyFile")
Pwd = SettingRead("TallyPass")
Application.ScreenUpdating = False
If Workbooks(WB).ProtectStructure Then Workbooks(WB).Unprotect Pwd
If Not FindSheet(WShe_spc, Workbooks(WB)) Then
Workbooks(WB).Worksheets.Add Workbooks(WB).Worksheets(1)
Workbooks(WB).Worksheets(1).Name = WShe_spc
End If
For Each WSh In Workbooks(WB).Worksheets
If WSh.Name <> WShe_spc And WSh.Visible <> xlSheetVeryHidden Then WSh.Visible = xlSheetVeryHidden
Next
Workbooks(WB).Windows(1).Visible = False
DoEvents
Workbooks(WB).Protect Pwd, True
ThisWorkbook.Activate
Application.ScreenUpdating = True
End Sub
Sub TeeOpen_UnprotectTee(Wb)
' Unprotect a Tee file that was protected by TeeOpen_ProtectTee sub above
If WB = "" Then WB = SettingRead("TallyFile")
Pwd = SettingRead("TallyPass")
Application.ScreenUpdating = False
Workbooks(WB).Unprotect Pwd
Workbooks(WB).Windows(1).Visible = True
For Each WSh In Workbooks(WB).Worksheets
WSh.Visible = xlSheetVisible
Next
ThisWorkbook.Activate
Application.ScreenUpdating = True
End Sub

WB
If passed as "" it will need to read from Settings sheet

Views 1573 Downloads 554

VBA-Excel Protection
ANmarAmdeen
755
Attachments
Revisions

v1.0