View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Daffo Daffo is offline
external usenet poster
 
Posts: 13
Default how to declare local variables for Excel.Workbook at runtime.

Hi i want to how to declare local variables for Excel.Workbook object
at runtime using C#.

Suppose i have a dropdown which contains the list of excel files in a
folder.
Say there are 3 files in a particular folder. july.xls,
august.xls,september.xls. Each time the user selects a file i declare a
variable xlbook of type Excel.Workbook and open tat wbook.

Excel.Application xlApp=new Excel.Application();
Excel.Workbook
xlbook1=xlApp.Workbooks.open("c:\\july.xls",missin g.value,missing.value....);
Excel.Workbook
xlbook2=xlApp.Workbooks.open("c:\\august.xls",miss ing.value,missing.value..);
Excel.Workbook
xlbook3=xlApp.Workbooks.open("c:\\september.xls",m issing.value,missing.value);

I want to know if i can declare xlbook1,xlbook2,xlbook3 at runtime...

for(N=1;N<=no_of_excelInFolder;N++)
{
Excel.Workbook xlBookN;

}

Where xlBookN=xlBook1,XlBook2...etc

If this is not possible i atleast want to declare a new local variable
for each of the excel file in the folder. like

Excel.Workbook a; Excel.Workbook b; Excel.Workbook monday; I just
want the name of the local variable to be unique for each
Excel.Workbook object that is created.

With Regards
Daffo