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: 

Change the order of excel worksheets and delete worksheet

Hi,

I am using LV7.1.

I want to save array data into excel worksheets.

I do this base on the example "write table into XL.vi"

the problems are :

1. the order of the worksheet is 2,1,0, but what I want is 0,1,2. I try to change the order, it is not successful. Also, I don't know what should I put in string and string1 for index.

2. There are 3 extra worksheets, sheet1, sheet2, sheet3, as I inport data after adding a new worksheet. How can I delete the 3 extra worksheets?

excel.jpg

Can anyone hepl me?

Thank you so much!

 

The vi called write array into excel in the dll is attached.

Download All
0 Kudos
Message 1 of 2
(2,651 Views)

@Edith wrote:

1. the order of the worksheet is 2,1,0, but what I want is 0,1,2. I try to change the order, it is not successful. Also, I don't know what should I put in string and string1 for index.


This is happening because in your use of the Add method you did not specify anything for either "Before" or "After". You have to look at the documentation for the Excel properties and methods to understand how they work. This is documented on the Microsoft web site. The documentation for the Add method says (this is from Office 2003, but applies to 2007 as well):

 

Creates a new worksheet, chart, or macro sheet. The new worksheet becomes the active sheet.

 

expression.Add(Before, After, Count, Type)

expression Required. An expression that returns one of the above objects.

Before   Optional Variant. An object that specifies the sheet before which the new sheet is added.

After   Optional Variant. An object that specifies the sheet after which the new sheet is added.

Count   Optional Variant. The number of sheets to be added. The default value is one.

Type   Optional Variant. Specifies the sheet type. Can be one of the following XlSheetType constants: xlWorksheet, xlChart, xlExcel4MacroSheet, or xlExcel4IntlMacroSheet. If you are inserting a sheet based on an existing template, specify the path to the template. The default value is xlWorksheet.

Remarks

If Before and After are both omitted, the new sheet is inserted before the active sheet.

 

As you can see, since you did not provide any values for Before and After, the new sheet will get inserted before the active sheet. Thus, in the second iteration, sheet "1" will get inserted before sheet "0".

 


2. There are 3 extra worksheets, sheet1, sheet2, sheet3, as I inport data after adding a new worksheet. How can I delete the 3 extra worksheets?

You have to delete these yourself from the Sheets collection. You have to first select the sheet using the Item property of the Sheets collection, which will give you a reference to the sheet, and then you can call the Delete method for that sheet.

 

I would strongly suggest heading over to the Excel thread and getting the Excel toolkit that available there as it will provide a good starting point. NOTE: DO NOT POST QUESTIONS IN THE EXCEL THREAD!!!!

 

 

Also, you really should read the LabVIEW Help on autoindexing of for-loops. You are currently autoindexing the loops and also wiring the number of iterations. Do not do this. If you are autoindexing you should not wire the number of iterations since LabVIEW already knows how many iterations to perform.

0 Kudos
Message 2 of 2
(2,642 Views)