I am writing some code for a company that will use it on its network. I am not online like theirs to check, so I check to make sure that the code is correct for the first time!
The book will interact with other sheets on its network in various ways, and essentially I need to be able to check if:
- The target workbook is already open in its own system and Ideal:
- Is it open in the same instance of Excel or
- Is it open in a separate instance (I believe that this may require different actions for copying and pasting ranges, saving, etc. what I need to know more about)
- The target book is opened by another network user (so suppose it will be opened for reading only)
I came across a lot of questions about checking if a workbook is open, for example: http://support.microsoft.com/kb/291295
But I did not find anything that would clearly differ from the two scenarios described above.
thank
Update
Now I use:
Function IsFileOpenInInstance(FileName As String)
Dim ShortFileName As String
Dim ValidOpenFile As Boolean
Dim ErrNum As Integer
On Error Resume Next
ShortFileName = Dir(FileName)
If FileName = Workbooks(ShortFileName).FullName Then ValidOpenFile = True
ErrNum = Err
On Error GoTo 0
If ErrNum <> 0 Then
IsFileOpenInInstance = False
Else
IsFileOpenInInstance = ValidOpenFile
End If
End Function
source
share