From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Activex Excel Automation: the Missing Handle

Once upon a time there was a piece of legacy code, working well.  It would open Excel workbooks, add data, and make it look nice.

Then one fateful day, the old code creaked and groaned, and it doesn't work the same way it used to when it was fresher and younger.

 

Now when the code runs, an excel 2007 reference is not closed somewhere, causing the excel.exe process to remain open after the code has finished execution.

 

With great care, I have extracted all the extraneous code from the process, so that only a few base functions remain; yet the problem persists!  For your convenience, I have flattened it all onto the same vi pane (the old code is rather modular)!  Apologies for any extraneous wire bends 😃

 

My questions are threefold:

What changed that caused this code to stop working? 

Is there a better way to find and close activex references than staring intently at the wires?

Is there, dear reader, perhaps a blatent error in the old code?

 

 

0 Kudos
Message 1 of 62
(3,804 Views)

Close the references after you are done with all the tasks in your VI.

0 Kudos
Message 2 of 62
(3,797 Views)

Could you please be a bit more specific?  Which reference are you referring to?

0 Kudos
Message 3 of 62
(3,793 Views)

ALL of them.

Look at the examples included with LabVIEW.

0 Kudos
Message 4 of 62
(3,791 Views)

I"ve moved all the CR's to the end of the VI.  The problem persists.  Look at the examples? Are you toying with me?

0 Kudos
Message 5 of 62
(3,786 Views)

Why would I be toying with you????

 

I have written to Excel all the time from LabVIEW, VB.NET, and VB6 and the problem you mention is real one.

0 Kudos
Message 6 of 62
(3,778 Views)

I kid, I kid. 

 

After looking closely at the examples, the code is almost exactly like 'Write table to XL.vi'.  The difference is the activesheet reference opening as a variant under the _workbook property node.

 

If I eliminate it from the code, it fixes the problem.  However, I need to be able to specify 'Before' and 'After', so I would prefer to find a way to make it work.

 

Thank you for your assistance.

0 Kudos
Message 7 of 62
(3,775 Views)

I can't tell the purpose of the ActiveSheet Add/Before function?

Are you trying to specifiy an ActiveSheet or create a new Worksheet in addition to the 3 that is standard?

 

0 Kudos
Message 8 of 62
(3,764 Views)

See 'Open new worksheet.vi' in the examples.  It's the same purpose, to create a new worksheet in the workbook, but with the ability to specify it's order relative to the currently selected worksheet.

0 Kudos
Message 9 of 62
(3,762 Views)

Further investigation is showing that the activesheet reference, once created, is not closing properly.  Unfortunately, a large amount of other code depends on activesheet references behaving nicely.  Is the excel.worksheet constant used as type for variant to data correct?  What else could be wrong with it?

0 Kudos
Message 10 of 62
(3,751 Views)