0

How do I check whether a certain worksheet exists in the workbook? If not, go to next workbook. If yes, perform certain actions on it. I am looping through multiple workbooks.

Function WorksheetExists(app173 As String, Activeworkbook wb As Workbook) As Boolean
         Dim app173 As Worksheet

         Not sure what steps to include here in my case
End Function

Thanks!

  • Does this answer your question? [Test or check if sheet exists](https://stackoverflow.com/questions/6688131/test-or-check-if-sheet-exists) – Zephyr Mar 20 '23 at 14:52

1 Answers1

0

Find Worksheet in Multiple Open Workbooks

Sub FindWorksheet()

    Dim wb As Workbook, ws As Worksheet
    
    ' Caution! This also references hidden workbooks (e.g. PERSONAL.xlsb).
    For Each wb In Workbooks
        On Error Resume Next
            Set ws = wb.Sheets("Sheet1")
        On Error GoTo 0
        If Not ws Is Nothing Then ' found
            ' Perform actions, e.g.:
            Debug.Print wb.Name, ws.Name
            
            Set ws = Nothing ' reset for the next iteration
        'Else ' not found; do nothing
        End If
    Next wb
     
End Sub
VBasic2008
  • 44,888
  • 5
  • 17
  • 28