LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Check if a File is Open using the File Express VI

I haven’t programmed in LabVIEW for a while and need a quick refresher.

 

In my VI, users browse to a file on their local C:\ drive or OneDrive to retrieve its path. The file will always be an Excel file (usually .xlsx, sometimes .xls).

If the selected file is already open (via the File Express VI), Windows will display a message saying the file is in use—which makes sense, because that’s likely the file they intend to use.

 

Eric1977_0-1768926220935.png

 

Is there a way to let users browse to the file and suppress this message if the file is already open? Or is there a better approach? The goal is to get an Excel Object that I can pass around so I can use other Excel VIs within the Report Generation Toolkit.

 

Download All
0 Kudos
Message 1 of 13
(257 Views)

@Eric1977 wrote:
 
Is there a way to let users browse to the file and suppress this message if the file is already open? Or is there a better approach? The goal is to get an Excel Object that I can pass around so I can use other Excel VIs within the Report Generation Toolkit.

I cannot look at your VI unless you do a "save for previous", 2020 or below.

 

If the file is in use, it cannot be opened, so what exactly should the user see if this error occurs? Typically, you simply need to handle the error in the code (or turn off automatic error handling). "Handling" just means to wire the error out to something.

0 Kudos
Message 2 of 13
(242 Views)

@altenbach wrote:

If the file is in use, it cannot be opened, so what exactly should the user see if this error occurs? Typically, you simply need to handle the error in the code (or turn off automatic error handling). "Handling" just means to wire the error out to something.

That's what I thought too; just wire the error wire to something. Apparently, that does not seem to work, or I am not doing something correctly.

 

The user shouldn't see any popup message saying that the file is in use. I've had end users open the file they want to use BEFORE running the program & that popup message come up for them. I'd like to have them not see that.

 

I also saved the file as version 18.

0 Kudos
Message 3 of 13
(204 Views)

So why are you wiring an error dialog?

 

Why not use the "no dialog" option (instead of the default one button OK dialog). Or wire the error to literally anything else that does not care, e.g an empty sequence frame.

 

altenbach_0-1768933658922.png

 

0 Kudos
Message 4 of 13
(199 Views)

I think I misled you. It's not the error wire that I am having an issue with.

 

If you open an Excel Workbook then run that VI or use the File Dialog Express VI, you'll get a dialog box asking you where the file is located.

 

Eric1977_0-1768934304885.png

 

 

If you select the workbook that is already open, you'll get a Warning popup (I think) that says that the "file is in use."

 

Eric1977_1-1768934334828.png

 

 

THAT is the message that I want to suppress.

0 Kudos
Message 5 of 13
(190 Views)

@Eric1977 wrote:

I think I misled you. It's not the error wire that I am having an issue with.

 

If you open an Excel Workbook then run that VI or use the File Dialog Express VI, you'll get a dialog box asking you where the file is located.

 

Eric1977_0-1768934304885.png

 

 

If you select the workbook that is already open, you'll get a Warning popup (I think) that says that the "file is in use."

 

Eric1977_1-1768934334828.png

 

 

THAT is the message that I want to suppress.


I'm not quite sure what you are getting at, but some Express VIs have internal code where the error never comes out of the VI and gets output to the automatic error handler instead. Could this be one of those cases?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 13
(186 Views)

@billko wrote:
I'm not quite sure what you are getting at, but some Express VIs have internal code where the error never comes out of the VI and gets output to the automatic error handler instead. Could this be one of those cases?

You can open the express VI (right-click.. open front panel) and it is basically just a light wrapper around the old file dialog. All errors are wired.

 

If I open your file in excel and then run your VI by pointing at the open file, It just pops the excel window of the already open file. I don't get the error you are seeing.

 

0 Kudos
Message 7 of 13
(171 Views)

I can confirm I also downloaded your Excel file, opened it in Excel, then ran your VI in LV2023. I selected your file, and the VI completed without showing any popups, error or otherwise...

 

BUT if I put it in a location backed up by OneDrive, I can reproduce the error.

 

To those who can't reproduce the error, FYI- this happens IN the Browse window, not in LabVIEW. Basically you browse to the file, and when you double click to select it you get the popup OP is seeing. The Browse window stays open- it literally won't let you select that file.

 

Digging into the ExpressVI, it turns out this is happening within the core "File Dialog" VI itself. It literally will not let you select an open Excel document.

 

OP, I'm not sure how to fix this one... you might be able to do some shenanigans with Windows and Excel API's to see if Excel's open or not.

 

Edit: There are other people asking about this same thing. It's not a LabVIEW issue but a OneDrive one:

 

https://techcommunity.microsoft.com/discussions/windows10space/this-file-is-in-use-error/729073

 

Message 8 of 13
(159 Views)

You can also generate the error by trying to open the "~$..." hidden/system file that Excel creates when a file is open, even outside of OneDrive.

 

JePe1_0-1768937539603.png

JePe1_1-1768937588949.png

 

 

It seems like the File Dialog is responding to some kind of low-level Windows message. I can't think of any way to supress it, if NI didn't provide one.

0 Kudos
Message 9 of 13
(153 Views)

Microsoft OneDrive is the culprit.

 

I'll have to investigate this more, but, when I moved it off of the OneDrive/SharePoint system & to my hard drive, that error went away.

 

Edit: You guys beat me to it.

0 Kudos
Message 10 of 13
(152 Views)