David Hedrick
David Hedrick

Reputation: 51

C# Microsoft.Office.Interop.Excel will not open Excel Window

I have a main method here that is simply trying to open an excel workbook. This same script works on other machines, but I can't get it to work on this machine. It starts a background EXCEL.exe process, but does not open an excel window.

If I end that process in the task manager, and then open excel, it shows the workbook in the mySheet string variable in the document recovery pane. So something opened. I just couldn't see it. What am I missing here?

Using a Console Application in Visual Studio 2017. Excel 2016 64 bit.

using Excel = Microsoft.Office.Interop.Excel; 

static void Main(string[] args)
    {
        try
        {
            string mySheet = @"C:\\Users\\dwh002\\Documents\\ZIP_COUNTY_032017.xlsx";
            var excelApplication = new Excel.Application();
            excelApplication.Visible = true;
            var workbooks = excelApplication.Workbooks;
            var workbook = workbooks.Open(mySheet);
        }
        catch (Exception)
        {
            throw;
        }

Upvotes: 2

Views: 3387

Answers (1)

David Hedrick
David Hedrick

Reputation: 51

The moving the Visible = true line below the workbooks.Open line worked. I'm not sure why this machine is the only one having trouble with the code in this order, but I'm glad it worked.

Upvotes: 2

Related Questions