LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX Excel Prevent Open File While Writting

I'm having some of the same problems with Excel and ActiveX found here:
 
The last post from the above link gives an acceptable workaround (not ideal, but hey, what can you do?) to preventing the user from closing Excel when files are being written to with ActiveX through LabVIEW (since a user can open an Excel file while LV is writting to Excel files with ActiveX and all the files will share the same Excel application, instead of Excel opening a seperate application like one would hope).
 
My question for this post: In the previous post Ben had a problem with the user opening a different Excel file than those being written to. My VI opens an exisiting Excel file (test.xls) and writes to it. If the user opens test.xls while LV is still writting test.xls, it will throw an error. Note that the error is not thrown if test.xls is open before the VI starts writting to it, only if the user opens it while its being written to by LV.
 
Any ideas on how to lock the file so the user can't open it while it is being used by LV?
 
Michael
0 Kudos
Message 1 of 3
(3,064 Views)
View my reply in the thread you mention. Hope that helps. I tried EVERYTHING else before this solved all problems. Sorry I'm not able to post a pic, doesn't seem to work for me.
Certified LabVIEW Architect
Message 2 of 3
(3,010 Views)

Thanks thols. Thats a great solution, I actually had tried it but gave it up since the user could close out of "their" Excel (closing the reference), then open a new spreadsheet which would open in "my" Excel (if done while my subVI was still writing to Excel). At the time, this was a possible scenario for my program, and since I was writing so slowly had happened. I just sped up the writing of the Excel file (I had all the data to write, but was writing with "Set Cell Value.vi", which wrote one cell at a time; instead I wrote whole ranges of data). If Excel was already open, I would set interactive to false and have my spreadsheet minimized while writing to it. If Excel wasn't open, I would just make it invisible. Since I cut the time down to about a second, this worked for my application.

Michael

0 Kudos
Message 3 of 3
(3,004 Views)