LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error 5 - File Already Open occurs with no instance of Excel open.

Solved!
Go to solution

Questions regarding my particular problem have been posted many times and I have researched them all.  But this problem is slightly different from what I have found on the forum.  This issue I have been fighting for the past two weeks and I can't seem to find a solution for it; therefore I turn to you in the hope that someone with more experience can point me in the right direction.

 

I am getting Error code 5 - File Already Open in my application.  I know the most common response, a reference hasn't been closed, but I have checked and all references appear to be closed.  The Error code.VI attached is not my application, but a simple file I/O routine I created after Error code 5 came up.  The screenshot shows tack manager;  although you cannot see the entire list, Excel does not appear anywhere in it, yet it still shows that the particular .xls document I am trying to open is already open.  This is where my problem deviates from everything else I have read.  Here's the head scrather, I still get this error even after killing Excel using the System Exec.VI.  The Excel instance is clearly removed from the task list, but the error still gets generated by the Write to Spreadsheet File.VI.  The second string indicator shows the contents of the task list for your viewing.  I cannot find an open instance of Excel anywhere, so I do not know why LV thinks the file is already open when it is not.  There must be a reference open for it to think this, but why does it not show up in Task Manager?  The .zip file contains my VI along with it's sub-VIs.

 

Thanks in advance for any assitance you can provide.

 

Reese

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Download All
0 Kudos
Message 1 of 14
(15,052 Views)

It worked for me without producing an error. I am using Windows 7 and ran your Excel Run Status without any trouble. There was a SubVI missing - Get Task List.vi. I put a digram disable on all the code in Search Task Bar.vi and ran it.

 

[Edit: I get error 5 if I have the document open in Excel. If I close the document but do not close Excel I get error 2 but that might be something to do with the code I commented out. If I close Excel I can overwrite the document I just created and opened]

=====================
LabVIEW 2012


0 Kudos
Message 2 of 14
(15,043 Views)

I have seen the LV environment hold a file hostage until I restarted LV.  You may be seeing something similar.  As I recall it had something to do with my code.

0 Kudos
Message 3 of 14
(15,036 Views)

I didn't get the error until I had Excel opened.  The program will prompt you to close Excel if it finds it in the taskbar.  It will automatically close it if it finds it in the tasklist but not the taskbar.  I should also note that I am opening .xls files from attachments on my e-mail.  I don't think that should make a difference.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 4 of 14
(15,035 Views)

@Wayne.C wrote:

I have seen the LV environment hold a file hostage until I restarted LV.  You may be seeing something similar.  As I recall it had something to do with my code.


Wayne.C,

 

That's very possible.  It does appear that I have a hostage situation here.  The error does clear when I restart LV.  Do you recall what the issue was with your code?

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 5 of 14
(15,033 Views)

MoReese,

 

I know that one time this happened an error was generated during the editing of an Excel doc ( report gen toolkit ) and prevented the report being properly disposed. 

0 Kudos
Message 6 of 14
(15,027 Views)

I have suspected that is where the problem lies (RGT), but the error in my app is coming from the Write to Spreadsheet File VI (but it could be related to the RGT in an early step or loop).  I am in the process of disabling any newly added code from the past couple of weeks (that I can think of) to see if the problem goes away.

Any other suggestions or insights are welcome.  Thanks.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 7 of 14
(15,017 Views)

OK, I have confirmed where my error is occurring.  It is not happening in the RGT as I initially suspected but directly after in my g-mail.VI which is using .NET contructs.  This VI has been posted a couple of times here on the forum and this is where I downloaded it from.  Can someone please confirm what I am seeing.

 

At the end of the chain, open the file that is being attached (in my case I am attaching an .xls document) using Open/Create/Replace file function; although, using Write to Spreadsheet File gives me the same error as well.  I am getting Error code 5 - File Already Open.

 

I have verified that the reference being created by the contructor node Attachment>>FileName is causing the error.

You will notice there are no close reference functions in this VI.  This is the VI that was downloaded and I have confirmed it generates this error.  I have tried closing the references to no avail.  For some reason the .NET constructor is holding this reference hostage and preventing me from opening this file later on.

 

What am I missing?  I have spent an enormous amount of time already trying to track this problem down through debugging and research.  Perhaps this VI has not been used that much and no one has reported this issue before.

 

Any insight into this problem would be appreciated.  Thanks for your assistance.

 

Edit:  The Gmail v86-1.VI contains the code for opening the file for your convenience.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Download All
0 Kudos
Message 8 of 14
(14,998 Views)
Solution
Accepted by topic author MoReese

I found the problem.  The close reference does not work with file attachments in .NET objects.  In the Invoke node for AttachmentCollection, there is a method called "Dispose" which kills the reference created with the fileName object. I have also attached the VI.

 

.NET Error 5 with file attachment.JPG

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Message 9 of 14
(14,986 Views)

 


@dfgdfgd wrote:

repair Excel files Microsoft is able to find out, scan and recover excel files all formats. It restores fonts, columns, rows, formulas, worksheets and etc. excel data. Utility has the compatibility with Win 98 and higher. Try its facilities download demo




 

What does that have to do with this 3 month old thread?

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 10 of 14
(12,526 Views)