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: 

Excel and .NET Problems

Solved!
Go to solution

I know there is the RGT toolkit which I have and ActiveX which works, however, I would like to know if anyone has a solution to this problem using .NET. (@PhilipBrooks, .NET guru, if you are reading this.)

 

I am having problems determining the number of workbooks open with Excel and whether a particular file is open. Note the ActiveX versions posted here DO WORK, however I want to know why the .NET solutions do not work.

 

PNGs and VIs are attached.

 

Thanks for your help.

 

Regards,

mcduff

 

ActiveXCount.png

 

getReftoOpenEcel.png

 

 

 

 

Download All
0 Kudos
Message 1 of 16
(4,434 Views)

Can you post the VIs for 2016 or earlier?

0 Kudos
Message 2 of 16
(4,416 Views)

Thanks for looking into this.

 

mcduff

Download All
0 Kudos
Message 3 of 16
(4,412 Views)

I've had no success yet, but based on this article I think you want the _Application property. The ApplicationClass is reserved for internal use. But when I select _Application it says no public constructors are available...

Message 4 of 16
(4,401 Views)

@Gregory wrote:

I've had no success yet, but based on this article I think you want the _Application property. The ApplicationClass is reserved for internal use. But when I select _Application it says no public constructors are available...


No, I think the ApplicationClass is correct.  However mcduff's code is creating a new instance of Excel, not grabbing the already opened instance.  If you put an ApplicationClass.Visible = True, you can see it flash onto the screen and then close. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 5 of 16
(4,385 Views)

This still does not work, but you can convert to a more specific type to the _Application Class, even when I use this class I can not get the count or find item. I think aputman is on the right track, we need a reference to the excel application that is running.

 

mcduff

snip.png

 

 

 

0 Kudos
Message 6 of 16
(4,370 Views)
Solution
Accepted by topic author mcduff

There is a way to do this in C# but I haven't figured out how to port this over to Labview .NET.

 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 7 of 16
(4,351 Views)

I think you are on the right track. Based on your previous comment, I too have been looking for the "GetObject" call in .net to try and get the current instance of excel. However, I cannot find it in any of the libraries that supposedly have it. I think if we can find that, then it may/should work.

Thanks again for looking.

 

Cheers,

mcduff

0 Kudos
Message 8 of 16
(4,346 Views)
Solution
Accepted by topic author mcduff

Thanks for your hints I think a found a solution to get the current instance of excel. Thanks for your help.

 

See snippet and VI.

 

mcduff

snip2.png

 

 

 

Message 9 of 16
(4,336 Views)

Awesome.  I will have to take a look at this on Monday because I couldn't figure out how to get the Marshal object.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 10 of 16
(4,328 Views)