LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Is it possible to programatically determin if an Excel file is already open or not"

I mean Excel does tell you if you are trying to open a file that is already open on the network or on ur pc but I want to be able to find out before I can do anything if the file I want is already open or not...

The reason being if I just let Excel alert me when a file is already open, I cannot control what happens after that, I looked at the Error code that is produced when you click on 'don't open file'and its the same error code that is produced when the Excel file can't be found '-2146827284'. I am using active X by the way so I wanted to be able to alert the user that the file is already open and then do somthing else after, also if the file can't be found, I wanted to alert the
user accordingly, but most importantly I wana be able to check if the file is already open or not before I can use it. Can anyone help on this?
Thanks
0 Kudos
Message 1 of 4
(2,915 Views)
Hi,
you can use at first the File Info function (advanced LV file function)to see if file exists: if not it returns error code 7.
If it exists you can then open it by activeX functions, if an error occurs, the file is already open.
Hope it helps,
Alberto
0 Kudos
Message 2 of 4
(2,914 Views)
So thats basically saying that at most, there can only be 2 common errors you are most likely to encounter when opening a file (an Excel file in this case and using Active X), 1 is if the file can't be found for whatever reason and the other if the file is already open? I guess if thats the case then the idea you suggested will be useful but am just thinking whether thats good coding or not because I dont want any other error that I have not looked out for to pop up when least expected when dealing with the file, so basically there seems to be no specific way of determing whether the file is currently open or not programatically?

How does windows know then if a shared file is currently open or not then, what does it use or is this question venturing into de
ep waters?
0 Kudos
Message 3 of 4
(2,914 Views)
You can open the workbook as ReadOnly. This will prevent an error if the book is already open, but will still show an error if the file is not found.

If the book is opened successfully, use the Invoke Node ChangeFileAccess with a mode of Read/Write. This should generate an error if the file is already open for editing somewhere else on the network.

Michael
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 4 of 4
(2,914 Views)