Checking if wb is open - code failing

  • Hi all,

    Here is my code for checking if a workbook is open; unfortunately, it is failing on the second Set line below:

    Dim LastRow As Long, wb As Workbook, WbookCheck As Workbook, fd As Office.FileDialog, MsgStr, sFile As String
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
        On Error GoTo ErrorHandler:
        Set WbookCheck = Workbooks("Job Expenditure Review.xlsm")

    When using F8 scrolling through the procedure, the variable WbookCheck is Nothing, and that is why it is failing.

    It was working before, so I think I must not have something in the right order - and cannot remember what order they were in before, LOL.

    Can someone see my mistake?

  • Here is the Test Sub() I created first, and this works ok:

    btw, in my actual code, I reference the sources used for code which is not my own

  • LOL, found the error. When F8'ing through the Test Sub, it was clear the following line was being ignored:

    Set WbookCheck = Workbooks("Job Expenditure Review.xlsm")

    So, deleting this line fixed the error!! " :stare:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!