navpreet1983
Programmer
I have the code to open a new Excel workbook, but can't seem to know how to open an existing file from say my C drive. Here is the code I have...any help would be great! Still new to C#.
Essentially, the second last line of code "oWB = ..." should open a file, say in C:\abc.xls. Once I have control of the workbook I can do the rest. :-s
Thanks in advance.
Code:
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;
try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = true;
[green]//Get a new workbook. But need an old file. [/green]
[red]oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));[/red]
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
Essentially, the second last line of code "oWB = ..." should open a file, say in C:\abc.xls. Once I have control of the workbook I can do the rest. :-s
Thanks in advance.