Checking If A Sheet Exists In An External Closed Workbook

前端 未结 3 1529
星月不相逢
星月不相逢 2021-01-14 20:11

I want to test whether certain sheets in the current workbook exist in another closed workbook and return a message saying which sheet/s are causing errors.

I prefe

3条回答
  •  囚心锁ツ
    2021-01-14 20:45

    Just an update for Tim's Function for error Handling:

    VBA:

    Function HasSheet(fPath As String, fName As String, sheetName As String)
    On Error Resume Next
    Dim f As String
    
    f = "'" & fPath & "[" & fName & "]" & sheetName & "'!R1C1"
    
    HasSheet = Not IsError(Application.ExecuteExcel4Macro(f))
    If Err.Number <> 0 Then
        HasSheet = False
    End If
    On Error GoTo 0 
    End Function
    

提交回复
热议问题