我正在跟进我之前的问题,我选择使用一个函数并构建了一个工作表名称列表,这些工作表是正在执行的任务的例外
Function exception(Sheet_Name As String) As Boolean
Dim exceptions(3) As String
Dim Counter_x As Long
exceptions(0) = "MASTER ITEM LIST"
exceptions(1) = "ITEM LIST"
exceptions(2) = "Rebar Protperties"
exceptions(3) = "Rebar Worksheet"
exception = False
For Counter_x = LBound(exceptions) To UBound(exceptions)
If Sheet_Name = exceptions(Counter_x) Then
exception = True
End If
Next Counter_x
End Function
在这种方法中,工作表名称是硬编码的。我也曾一度采取了一种方法来处理例外情况worksheet("blah").index > 2。使用索引号似乎是个坏主意,因为可以移动工作表,这会改变其索引号。在列表中对工作表名称进行硬编码似乎也是一个糟糕的选择,因为可以重命名工作表名称。