I'm trying to write some code that will identify if a certain file is already open. If it is, then I want a msg box to appear. If it isn't, then I want some other code to run. I did some searching, and found some code that looks like it would work. I implemented that coding into my application, but it's not catching the open file. I'm not sure where I went wrong here.
Code:
Function IsWorkBookOpen(Name As String) As Boolean
Dim xWB As Workbook
On Error Resume Next
Set xWB = Application.Workbooks.Item(Name)
IsWorkBookOpen = (Not xWB Is Nothing)
End Function
Private Sub cmd_Export_6827_Click()
Dim xRet As Boolean
xRet = IsWorkBookOpen("6827_BKR371.xls*")
If xRet Then
MsgBox ("Please ensure that all 6827_BKR371 files have been saved, and closed before proceeding.")
Else
Call Export_6827_BKR371
Unload Me
End If
End Sub