troubleshooting Question

check whether workbook contains a specific worksheet using VBA

Avatar of Andreas Hermle
Andreas HermleFlag for Germany asked on
VBAMicrosoft ExcelMicrosoft Office
17 Comments1 Solution121 ViewsLast Modified:
Dear Experts:

below macro checks if a file exists in a specific folder.

I would like to expand the macro to accomodate the following requirement.

If the file is found, the macro is to further check whether a specific sheet by the name 'Overall_List' is present in the workbook.

If not, the macro is to say so and the macro is to abort.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas



Sub File_Exist_With_Dir()
    Application.ScreenUpdating = False
    Dim FilePath As String
    FilePath = ""
    On Error Resume Next
       FilePath = Dir("C:\MyFolder\MyDocuments\Isele\ProductList.xlsx")
    On Error GoTo 0
    If FilePath = "" Then
        MsgBox "File doesn't exist", vbInformation, "File not found"
        Exit Sub
    Else
        MsgBox "File exist", vbInformation, "File exists"
        Call MyNewFile
    End If
    Application.ScreenUpdating = False
End Sub


Sub MyNewFile()

MsgBox ("hello")

End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros