Hi,
I have the following code that works perfectly on a Windows machine, but generates that compile error on a Mac.
The piece of code that blows up is ".Unprotect" in this simple loop:
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:=pWord
Next ws
The entire macro where that code snippet lies is:
Sub Protection_Off()
Dim pWord As String
Dim ws As Worksheet
pWord = InputBox("Please enter the password", "Model Protection")
If pWord = "" Or StrPtr(pWord) = 0 Then
Sheet2.OLEObjects("opt_AdministrationSheets_Hide").Object.Value = True
Exit Sub
End If
On Error GoTo ErrorTrap1
Application.ScreenUpdating = False
' Workbook protection
ActiveWorkbook.Unprotect Password:=pWord
' Worksheet protection
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:=pWord
Next ws
For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
NamedRanges_Show
TableOfContents_ShowAdminRows
' Make the ToC tab the active window
Application.Goto reference:=Sheet2.Range("A1"), Scroll:=True
MsgBox "Protection disabled.", vbExclamation, "Model Protection"
Application.ScreenUpdating = True
Exit Sub
ErrorTrap1:
Sheet2.OLEObjects("opt_AdministrationSheets_Hide").Object.Value = True
Application.ScreenUpdating = True
MsgBox "Password incorrect - protection still enabled.", vbExclamation, "Model Protection"
Exit Sub
End Sub
Thanks for any guidance on this!
Lawrence
Bookmarks