02-10-2024 05:16 AM - edited 02-10-2024 05:17 AM
I have build this VI that utilizes ActiveX domains to append data into excel. The only problem that I come across is the excel application not closing totally. I can't find the reference that keeps open the excel application.
Can anyone suggest a solution to my problem?
The files are in labview 2023.
02-10-2024 05:59 PM
Well, we try to educate "New Members" to understand that many of the more-experienced LabVIEW users don't buy a new version every year. I'm running LabVIEW 2019, and cannot open your LabVIEW 2023 VI.
You say you are using ActiveX to interact with Excel. Question -- are you using the functions in NI's Report Generation Toolkit? Specifically, are you opening Excel using "Create Report"?
I don't really know what happens "behind the scenes", but LabVIEW "does some magic" and opens Excel for you, and allows you to target it with ActiveX requests. There is another function, "Dispose Report", which LabVIEW calls to get Excel to close, and sever its connections with LabVIEW.
If you "create a Report" (by writing to a Workbook), you also need to save your Report to a file (an Excel file, of course), which you need to do before you Dispose Report. Something that I discovered a half-dozen years ago when saving data to Excel using LabVIEW was that sometimes the "Save Report/Dispose Report" sequence seemed to fail, particularly if I tried to reopen the Report. The solution was to put a short delay (50 msec? Don't remember the value) between these functions to let Excel "do its thing".
About a decade ago, I posted a Revised "Generate Excel Report" Example that illustrates how to use the RGT to make a simple Report with data in selected cells, and with a Graph on the same page. You should be able to find it by doing a search on the Forums. (I typed the name of the Example into Google and it found it ...).
Bob Schor
02-11-2024 06:35 AM
Hello Bob, thank you for your answer.
I converted the VI's in 2012 version of labview. Excuse me for the mistake!
I didn't use the report generation toolkit to append data into excel! I used the ActiveX domains, as you will see on the VI.
Thank you in advance.
02-11-2024 09:14 AM
When I first started using LabVIEW, the project I was handed (in LabVIEW 7) had over 700 VIs and almost 200 TypeDefs. It also used ActiveX to open an Excel Workbook with several Worksheets that were largely used as a template for carrying out a series of tests investigating the ability of large primates (mostly undergraduates) to localize a sound source without any visual cues.
I picked up LabVIEW fairly quickly (I'd been programming in a Macro language and in Pascal for a decade or so), but found ActiveX and the Excel interface awkward and slow. But we had access to the Report Generation Toolkit, which I adopted and found that (a) Excel was much more reliable (no more "crashes"), (b) much easier to integrate with LabVIEW, and (c) ran signficantly faster (I'd say at least a factor of 5, maybe more).
Look at the code fragment you just posted -- who can see the structure in there? Also, where are you opening Excel, where are you filling in cells (presumably some of that is in your attachment), where are you telling Excel to save its work, and where are you closing Excel?
Now look at the "Revised Example" that using the RGT. Fits on a single laptop screen, from opening Excel, to writing isolated cells and labels, and filling in a 2D table of data, plotting those data on a graph, saving the file as an Excel document, and closing Excel and exiting. What's not to like?
Bob Schor
02-11-2024 04:17 PM
The most likely problem is that you try to close the Actual Worksheet reference several times but it is only retrieved once through the Active Sheet property node. The fact that you split the refnum to multiple Worksheet.Range methods doesn't magically create new refnums. The first executed Close Reference will however close that refnum, and other Worksheet.Range calls if they happen later, or at least all the other Close Reference will create an error because the refnum is not valid anymore. After that all other functions won't be executed except the Close Reference node, which is executed anyways even on an error in. This means that your Excel.Quit method is not executed. Simple single step debugging, with highlighting enabled, would have shown you that in an eyeblink.
02-12-2024 04:06 AM
Hello rolfk,
Thank you for your answer. The VI was working perfectly without any errors. The only downside was the excel application not closing totally in the background (even this reference wasn't showing and errors).
Thank you again for your contribution!
02-12-2024 10:43 AM
Hello Dim_K
When I run your VI (`v1.vi', tried this in LabVIEW 2020) Excel does close but it takes a couple of seconds before it's removed from Windows Task Manager's PID listing when the Excel file already exists. If it does not exist, Excel is closed pretty much when `v1.vi' stops running.
After downloading the VI there was a minor error associated with the `Path of excel file' control, which was set to `File' (instead op `Folder').