我有以下4个代码在Windows PC上完美运行。 问题是,在Mac PC上使用它时无法正常工作。
我没有在mac平台上编码vba的经验,也没有调试代码的mac pc。
非常感谢在mac pc上转换或测试以下代码的一点帮助。
代码1:
Private Sub Workbook_Open()
Application.OnKey "^1", "HideSheets"
End Sub
代码2:
Sub HideSheets()
Dim myPassword As String
myPassword = "PASSWORD" ' Set password here
Password = InputBox("Enter Password")
If Password = "" Then Exit Sub ' Exit if no password iputted
' Incorrect password
If Password <> myPassword Then
MsgBox Title:="Warning", prompt:="Incorrect Password"
Exit Sub
End If
On Error Resume Next
' Correct password
If Worksheets("Services").Visible = True Then
Worksheets("Services").Visible = xlSheetVeryHidden
ActiveSheet.Protect myPassword, True, True
Else
Worksheets("Services").Visible = True
ActiveSheet.Unprotect myPassword
End If
End Sub
代码3:
Private Sub Auto_Close()
On Error Resume Next
Worksheets("Services").Visible = xlSheetVeryHidden ' Hide worksheets
ActiveSheet.Protect "PASSWORD"
ActiveWorkbook.Save
End Sub
代码4:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rRng As Range
Dim rCell As Range
Set rRng = ActiveSheet.Range("B17:B38")
If Not Application.Intersect(rRng, Range(Target.Address)) Is Nothing Then
Application.EnableEvents = False
With ActiveSheet
.Unprotect "PASSWORD"
For Each rCell In rRng.Cells
Select Case rCell.Value
Case "CASE 1", "CASE 2", "CASE 3", "CASE 4", "CASE 5"
rCell.Offset(0, 2).Value = 1
rCell.Offset(0, 2).Locked = True
Case Else
rCell.Offset(0, 2).Locked = False
End Select
Next rCell
End With
ActiveSheet.Protect "PASSWORD"
Application.EnableEvents = True
End If
End Sub
我可以使用下面的子程序来检查用户是使用mac还是使用windows pc。但由于我没有mac pc,如果我的代码工作正常,我就无法调试。
Sub WINorMAC_1()
If Mac Then
'Call the Mac version of the 4 codes above
Else
'Call each of the 4 codes above
End If
End Sub