Check If Excel Workbook is Already Open or Not

In my case, I work a lot with transferring data from current Excel Workbook to another Excel Workbook, and to be able to do that, of course I need to make sure whether the destination Workbook is already open or not.

The following excel vba function assigned to check whether a workbook we need is open or not.

Using Workbook name as an input parameter, the function will do a looping in Workbooks collection to check all opened Workbook name, if there is a Workbook with the same name with the Workbook that we looking for, then the function will return true, and false if otherwise.

Public Function CheckSourceAvailability(sWorkBook As String) _
  As Boolean
    Dim wb As Workbook, bResult As Boolean
    bResult = False
    For Each wb In Application.Workbooks
        If InStr(LCase(wb.Name), LCase(sWorkBook)) > 0 Then
            bResult = True
            Exit For
        End If
    Next wb
    CheckSourceAvailability = bResult
End Function

All information about opened Workbook was saved by Excel in a collection object called Workbooks, just like Worksheets collection used by Excel to save information about all the Worksheets available.

FIN.

This entry was posted in Cells and Range and tagged , . Bookmark the permalink.

11 Responses to Check If Excel Workbook is Already Open or Not

  1. Max says:

    Great function. The other 99% on the internet don’t work if the file is not saved!!

  2. Glad to hear that the function actually useful for someone else :D

  3. Worked for me when I exchanged

    If InStr(LCase(sWorkBook),LCase(wb.Name))
    to
    If InStr(LCase(wb.Name), LCase(sWorkBook))

    Thanks,
    Hemant Kathuria

  4. Pingback: debt consolidation companies

  5. Pingback: hud reverse mortgage

  6. Pingback: debt consolidation companies

  7. Pingback: debt management

  8. Pingback: reverse mortgage lenders

  9. Pingback: Xanax

  10. Pingback: hsbc credit card login

  11. Pingback: collagen pills

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>