Hi!

I try to open an existing excel file and have included namespaces and libraries as well but the highlighted words show errors. Please help.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel;
using Microsoft.Office.Interop.Excel;
 

namespace excel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application excelApp = new Excel.ApplicationClass();
            excelApp.Visable = true;
            Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
        0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
        true, false, 0, true, false, false);
        }

        
    }
}

If you're using a namespace using Microsoft.Office.Interop.Excel; you can't refer to types as Excel.Application or Excel.Workbook . You use just Application and Workbook.

Application is a reserved word in .NET. Use _Application or Microsoft.Office.Interop.Excel.Application instead.

HTH

Hi! Nice to hear that you got answer to your problem. Could you please mark the thread as solved. Thank you!

This question has already been answered. Start a new discussion instead.