I have this code:
using Excel = Microsoft.Office.Interop.Excel;
private void GetActiveExcelFile()
{
Excel.Workbook oWB;
object e;
try
{
(Excel.Application)Marshal.GetActiveObject("Excel.Application");
e = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (Exception ex)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
e = System.Activator.CreateInstance(type);
};
Microsoft.Office.Interop.Excel.Application oExcel = (Microsoft.Office.Interop.Excel.Application)e;
oWB = oExcel.ActiveWorkbook;
MessageBox.Show(oWB.Worksheets[1].Name);
}
If my file is ".xls" it work perfect, but if my file is Excel 2013, I got this error: 'object' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) Hope you can help me. Thanks a lot. Sorry If my English is terrible.