我正在尝试检查工作簿中是否存在命名范围,因为我编写的宏会遍历一个充满文件的文件夹。我在下面编写的宏适用于“正常”命名范围,但是当我将表名作为命名范围传递给函数时失败。
我在互联网上和其他地方搜索过为什么会出现这种情况,有人能指出我(可能很明显)做错了什么吗?
任何帮助,将不胜感激!
谢谢,
亚当
Public Function DoesNamedRangeExistInWorkbook(ByVal wb As Workbook, ByVal rangeName As String) As Boolean
Const FN_NAME As String = "DoesNamedRangeExistInWorkbook"
On Error GoTo catch
Dim rng As Range
Dim cellCount As Integer
Set rng = wb.Names(rangeName).RefersToRange
cellCount = rng.Cells.Count
DoesNamedRangeExistInWorkbook = True
finally:
Set rng = Nothing
Exit Function
catch:
Call ErrorReport(FN_NAME, False, Err.Number, Err.Description, rangeName & " could not be found in workbook: " & wb.Name)
DoesNamedRangeExistInWorkbook = False
Resume finally
End Function