LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel questions

I'm trying to use Excel from within my CVI application. The functionalities I wish to incorporate are general tasks like opening Excel, opening workbooks, etc.. I have two questions.

Question 1) If I opened a Excel through my CVI application and then close Excel manually outside of the application, I am unable to perform task through my application on Excel anymore. Attempting to do so will crash the application. Is there anyway to notify my CVI application that Excel has closed if I (or some end-user) do manually close Excel?

Question 2) If I have other Excel windows open, opened manually outside of my CVI application and I tell my CVI application to close the Excel it has opened, all the Excel windows end up closing, including the ones I op
ened manually outside of my CVI application. How do I remedy this so when I tell my application to close Excel, it only closes those that it opened.

Thanks.
Message 1 of 7
(4,473 Views)
Answer 1) Yes, you can get events from the Excel app when the user tries to close the application. You can override and not allow the user to close the app or you can do something else. There is an example program under cvi\samples\activex\excel called excelevents.prj that shows you how to do this if you are using the current version of CVI.

Answer 2) Excel is a multi-SDI user interface. That means it has multiple top level windows for one application. Any windows you open from the Excel application you are automating will be closed when that process is stopped. If you want other Excel windows open that do not go away, you would need to launch another instance of Excel and open the documents there. Hopefully, that makes sense.

Best Regards,


Chris Matthews
National Instruments
Message 2 of 7
(4,472 Views)
I have a question about the sample project "excelevents.prj". The callback function that is called when Excel initiates a event, "OnBeforeCloseBook", has a bunch of parameters such as workbook, a handle, etc...When this callback is called, how does it know what values are entered for those parameters?
0 Kudos
Message 3 of 7
(4,472 Views)
Those values are returned from Excel. Whatever workbook is clicked by the user, Excel sends back a handle to that workbook and that application so you can respond to the event by doing something with that workbook, such as save it, etc.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 4 of 7
(4,472 Views)
Hallo,
Thanks for your availability...
I'd like to know why I cannot correctly run the excel report instrument (having already loaded excel 2000.FP). When my CVI starts loading these instruments, a lot of build errors occur in the file excelreport.c for example:(  279, 87   Type error in argument 3 to `Excel_WorkbooksOpen'; found 'pointer to const char' expected 'pointer to char'.), and so on.
Thanks for your attention.
0 Kudos
Message 5 of 7
(4,130 Views)
Hi dyd1985,

Which Object Library are you using?  Under "Instruments", CVI should display "Microsoft Excel 9.0 Object Library" if you are using Excel 2000, but will have a different number if you load a different version.  The Excel Report instrument calls the 9.0 Object Library.  If you need to use a later version of Excel, you can go to the menu item Tools->Create ActiveX Controller... and choose the library for your version of Microsoft Excel.  Then you can change the function prototypes to match the version of the Object Library that you need to use.

Gavin Fox
Systems Software
National Instruments
Message 6 of 7
(4,090 Views)

Hi to all.

I have a question about excel CustomDocumentProperties. I need add one new property to excel workBook via activeX automation refnum. I use add method of CustomDocumentProperties. I wire name, value and type, but it's didn't work. Then how can I add some properties to Excel WorkBook?

0 Kudos
Message 7 of 7
(3,277 Views)