2

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;
        }
7
  • Did you check if the process is running as the user in question? Not as run as admin, local system or stuff. Commented Jun 15, 2017 at 19:43
  • I'm running it within Visual Studio as myself (I am an administrator on my machine). Could not get any simpler than that. I have a similar script that opens an Outlook Mail window using the Microsoft.Office.Interop.Outlook assembly that works perfectly fine. Something tells me it's something wrong with the Interop.Excel assembly. Commented Jun 15, 2017 at 19:48
  • You could try a Console.ReadLine() at the end, to stop your app from closing maybe some unwanted clean up happens. Commented Jun 15, 2017 at 19:54
  • Simpler would be running your program from the command-line. VS hides a lot of details from you. Commented Jun 15, 2017 at 19:54
  • 1
    Try moving the Visible = true line after the workbooks.Open line. I frustratingly can't reproduce your problem. Commented Jun 15, 2017 at 20:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. That also worked for me. but what's the reason ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.