Excel VBA file opened the same against another user

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 
+4
source share
1 answer
  • Due to the fact that Excel macros are allowed, Excel workbooks in one instance are distinguished by an unqualified name (file name without a full path).

    Try accessing to Workbooks("File Name.xls")find out if the workbook is loaded in the current instance, and if so, check the box FullNameto make sure it is really correct.

    , -, , . , (, GetObject("File Name.xls"), Excel, , ). , .

  • , . Excel, , , - .

0

Source: https://habr.com/ru/post/1543729/


All Articles