此子程序适用于Mac。但不是在PC上。我对受影响的一行进行了评论。 有任何想法吗?
Sub addEmptyProjectRow()
Call unProtectAll
Dim projectsTable As ListObject
Set projectsTable = Worksheets("Projects").ListObjects("PROJECTS_TABLE")
projectsTable.AutoFilter.ShowAllData
projectsTable.ListRows.Add (1)
projectsTable.Range(2, projectsTable.ListColumns("Lead").Index).Value = Application.username
' This line produces the error on PC
projectsTable.Range(2, 1).Select
Call protectAll
End Sub
un / ProtectAll看起来像这样
Public Function protectAll()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect UserInterfaceOnly:=True, AllowFiltering:=True, AllowUsingPivotTables:=True, AllowSorting:=True
Next ws
End Function
Public Function unProtectAll()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Unprotect
Next ws
End Function