Detect if another program currently has access to application

Exceljeanie

Board Regular
Joined
Jul 4, 2006
Messages
134
Hi all,
Scenario:
a vb.net Program is currently reading some informations from a workbook open in the Application.
This may take some seconds.
Is it now possible to detect in vba that this currently happens.

Thanks

Peter
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
try checking...

Code:
If Application.Ready Then ...

you can use a while loop to keep checking until ready maybe
 
Upvote 0
Hi,
Application.ready does not apply if another Program is working on Excel.
That was the first Thing i tested :-)
 
Upvote 0
Can you try this and see if it helps ...

The below code checks the Word document named "Test.docx" if it is in use or not.

Code:
Sub Test()
    Dim FileNum As Integer
    FileNum = FreeFile(0)
    On Error Resume Next
    Open ThisWorkbook.Path & "\" & "Test.docx" For Input Lock Read Write As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum]#FileNum[/URL] 
    If Err Then
        MsgBox "File is in use!"
    Else
        MsgBox "File is not in use!"
    End If
    Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum]#FileNum[/URL] 
End Sub
 
Upvote 0
May be its better to check if the file (Test.docx) exists and then check if it is in use or not ....

Code:
Sub Test2()
    Dim FileNum As Integer
    FileNum = FreeFile(0)
    MyFile = ThisWorkbook.Path & "\" & "Test.docx"
    If Dir(MyFile) <> "" Then
        On Error Resume Next
        Open MyFile For Input Lock Read Write As [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum"]#FileNum[/URL] 
        If Err.Number = 70 Then
            MsgBox "File is in use!"
        Else
            MsgBox "File is not in use!"
        End If
        Close [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum"]#FileNum[/URL] 
    Else
        MsgBox MyFile & " is not found!"
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,577
Messages
6,173,164
Members
452,504
Latest member
frankkeith2233

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top