Hi all
From a userform users can open numerous workbooks from command buttons. I am trying to stop users from opening a second copy if the workbook already open. I found and adapted the following code and it DOES stop a second copy of the workbook being opened but instead of displaying the "File already open" message, it displays the "opening file message. Have I missed something small???
Any pointers appreciated
Function IsOpen(wbName As String) As Boolean
Dim Wb As Workbook
On Error Resume Next
Set Wb = Workbooks(wbName)
If Err = 0 Then IsOpen = True
End Function
Sub TestTKSERVICE()
Const sFilName As String = "P:\My Documents\Truck Files 2008\TK Service.xlsm"
If IsOpen(sFilName) Then
MsgBox "Truck Service file is already open !"
Exit Sub
Else: MsgBox "Opening Truck Service file"
ChDir "P:\My Documents\Truck Files 2008"
Workbooks.Open Filename:=sFilName, Notify:=False
End If
End Sub
Bookmarks