LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX puzzle: How to close/cleanup IWebBrowser2 [Excel] Document?

Hello!

      Attached is a simple VI that uses the IWebBrowser2 (ActiveX) control to display an xls file.

The problem is that I need to access the IWebBrowser.Document property, but that causes Excel to stay open.

 

Run the VI with boolean=False and Excel will appear in the task manager for about 2 seconds.

Run the VI with boolean=True and Excel stays open indefinately (that is, until LabVIEW is closed).

 

Please help me figure-out how to get Excel to close!

 

Thanks in advance.

0 Kudos
Message 1 of 21
(4,152 Views)

I can't verify this, but my guess is that there's an implied reference to Excel that's left open. You could try explicitly closing the reference to the Excel app after closing the reference to the workbook.

0 Kudos
Message 2 of 21
(4,148 Views)

@550nm wrote:

Hello!

      Attached is a simple VI that uses the IWebBrowser2 (ActiveX) control to display an xls file.

The problem is that I need to access the IWebBrowser.Document property, but that causes Excel to stay open.

 

Run the VI with boolean=False and Excel will appear in the task manager for about 2 seconds.

Run the VI with boolean=True and Excel stays open indefinately (that is, until LabVIEW is closed).

 

Please help me figure-out how to get Excel to close!

 

Thanks in advance.


When posting VIs don't assume everyone has LV2011.

When I can't open a VI, it is hard to tell what is "wrong".

 

 

0 Kudos
Message 3 of 21
(4,144 Views)

Hi Smercurio,

      The attached code explicitly Quits Excel and closes reference yet Excel stays open!. I believe you're on the right track, though,  While investigating this on VB/Net forums someone recommends the .Net method "System.Runtime.InteropServices.Marshal.Release(Object)" to cleanup after accessing the Document object.  I just don't see "Marshal" (or "Finish") exposed in the LabVIEWs System.Runtime.InteropServices - any ideas here?

 

NOTE: Attached also fixes a bug - forgot to wire Set Occurrance in callback VI.

 

Thanks in advance!

0 Kudos
Message 4 of 21
(4,142 Views)

...sorry nyc, thanks for the reminder.Smiley Happy

Am attaching code in 9.0 - please let me know if it's broken.

 

Thanks!

0 Kudos
Message 5 of 21
(4,141 Views)

When I run your VI, the Excel workbook opens in Excel, it doesn't open in the web browser window.

I am running LV 2010 SP1 32-bit on Windows 7 64-bit.

And I have Excel 2010.

 

0 Kudos
Message 6 of 21
(4,138 Views)

I fixed my problem. There is a problem with opening Office 2010 documents in IE7 and IE8. For anyone interested, the solution is at http://support.microsoft.com/kb/982995

 

Anyone, I am not sure what you are trying to achieve with this VI.

 

Message 7 of 21
(4,127 Views)
Hi nyc,

The previously attached code has been cut out of a larger application.  It's only purpose is to reproduce the problem of not being able to close Excel.Smiley Wink

 

Cheers!

0 Kudos
Message 8 of 21
(4,126 Views)

Excel closes for me whether the Excel Open/Close is either true or false. There is not a residual Excel application running in Task Manager.

 

There are other ways to obtain the document properties of Office properties without going through all this gyration, but without knowing what you are trying to achieve it is hard to continue.

 

Good luck!

 

 

0 Kudos
Message 9 of 21
(4,118 Views)

Hi nyc,


@nyc_(is_out_of_here) wrote:

Excel closes for me whether the Excel Open/Close is either true or false. There is not a residual Excel application running in Task Manager.

 

There are other ways to obtain the document properties of Office properties without going through all this gyration, but without knowing what you are trying to achieve it is hard to continue.

 

Good luck! 


The problem comes when trying to use one of those "other ways" to update the sheet while IE is running a second instance of Excel which is also showing the sheet.

Try it.Smiley Wink

 

It's curious that the problem doesn't happen for you - can you change your copy to NOT close the ActiveX Workbook ref?  That should force Excel to stay open.

NI may have changed resource cleanup between 2010 and 2011, keeping the VI running might prevent Excel from closing - for TRUE case - on your platform.

 

Cheers!


 

0 Kudos
Message 10 of 21
(4,110 Views)