VBA检查一个sheet是否存在的函数

原创文章,欢迎转载:http://miao.blog/article/vba-sheet-exists

' 检查sheet是否存在
Public Function sheetExists(xBook As Workbook, sheet_name As String) As Boolean
    On Error GoTo ERR_HANDLING

    Dim xSheet As Worksheet
    Set xSheet = xBook.Sheets(sheet_name)
    sheetExists = True

    Exit Function
ERR_HANDLING:
    sheetExists = False
End Function
推荐阅读
传统的方式配置xlam比较麻烦,这段代码可以让你双击打开xlam时自动安装或更新
获取Excel的AddIn里边的Sheet对象
评论