VBA - Test if a CAD file is already open by an another user

VBA - Test if a CAD file is already open by an another user

felix.corre
Advocate Advocate
416 Views
2 Replies
Message 1 of 3

VBA - Test if a CAD file is already open by an another user

felix.corre
Advocate
Advocate

Hello,

I pilot AUTOCAD from excel VBA to execute mass routines for around 2000 plans. I would like to test if the CAD file is opened by another user.
I tried to test the presence of the DWL file but strangely it does not work.
Could someone help me?
Thanks.

0 Likes
Accepted solutions (1)
417 Views
2 Replies
Replies (2)
Message 2 of 3

seabrahenrique
Advocate
Advocate
Accepted solution

Hello,

 

This code bellow works to check if the file is already open in my own PC, but i guess the logic also can be implemented to check to another users, let me know about it:

 

Sub CheckIfFileIsOpen(filePath As String)

  On Error Resume Next
  Dim fileNum As Integer: fileNum = FreeFile()
  
  Open filePath For Input Lock Read As #fileNum
  
  If Err.Number <> 0 Then
  
    MsgBox filePath & " is already open by another user."
    
  Else
  
    Close #fileNum
    MsgBox filePath & " is not open."
    
  End If
  
  On Error GoTo 0
  
End Sub

Sub MakeATestHere()

    CheckIfFileIsOpen ("C:\?") 'PUT THE FULL PATH OF YOUR FILE HERE

End Sub

 

I hope can help u!

0 Likes
Message 3 of 3

felix.corre
Advocate
Advocate

Perfect, thanks a lot!

0 Likes