VBA TIPS
  Checking if the workbook has been opened.

Here is an example function returns True if the target workbook has been opened.

Example

Place the following in a standard module.

Option Explicit


Sub TestingFormula()
    If IsWkbOpened("Book1.xls") Then
        MsgBox "Target workbook has been opened"
    Else
        MsgBox "Target workbook has NOT been opened"
    End If
End Sub


Function IsWkbOpened(sWkbName As StringAs Boolean
'returns True if the target workbook has been opened
'returns False if the target workbook has NOT been opened
    Dim i As Long

    For i = Workbooks.Count To 1 Step -1
        If Workbooks(i).Name = sWkbName Then
            Exit For
        End If
    Next

    If i = 0 Then 'if the wkb did not found
        IsWkbOpened = False
    Else
        IsWkbOpened = True
    End If
End Function

| HOME |
Copyright © cellmasters.net - colo's junk room All Right Reserved
Tips and Information about Microsoft Excel|Masaru Kaji aka Colo