What I am trying to do is create a Windows App that opens some excel workbooks, does some calculations and the saves and closes the excel files.
I cannot seem to be able to focus on one of them without having to open them, like:
oBook1 = oBooks.Open("C:\\Reports\Excel1.xlsx");
oBook2 = oBooks.Open("C:\\Reports\Excel2.xlsx");
What I need to be able to do is to assign Excel1.xlsx to oBook1 and Excel2.xlsx to oBook2 when the excel files are already open.
Is there a away to do this? I have tried several ways found online but nothing works.
Until now I managed to do the assignment only by opening them one by one like the example above.
Thank you. Danut
Edit 1:
I am trying to get a list of excel workbooks open and then to select the one i need from there. My code is:
Microsoft.Office.Interop.Excel.Application oExcelApp;
oExcelApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
foreach (Microsoft.Office.Interop.Excel.Workbook WB in oExcelApp.Workbooks)
{
MessageBox.Show(WB.FullName);
}
oExcelApp = null;
When I try to assign oExcellApp I get the folowing error: "Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Application'. An explicit conversion exists (are you missing a cast?)"
What am i doing wrong?