Could not open excel file using Process.Start () in .Net4.0

Recently the old .Net 1.1 project is being ported to .Net4.0. The project uses the following method to open the excel file:

Process process = new Process();

  process.StartInfo.FileName = marco_file;


And marco_file is the path to the excel file with macros, for example "C: \ project \ test.xls" The macro in it will run immediately after opening the excel file.

In .Net1.1, both codes and the macro work well. In .Net4, codes are executed without exception. But the macro didn't work.

Why didn't the macro in the excel file run?

My environment is Win7 64bit. Office 2010 64bit. IIS 7.5


When I go to the following codes and start debug mode

process.StartInfo.FileName = marco_file;
if (process.Start())
    Debug.WriteLine("-->start ");
    Debug.WriteLine("-->failed ");


As a result, it goes into the else block, which means that the process does not start.

Does anyone know why?


source to share

1 answer

Check security in Excel. By default, Excel 2010 will disable macros when you open the workbook containing them, and you must explicitly enable them.

To enable macros you need to go to:

File tab on the ribbon => Options
                       => Trust Center
                       => Trust Center Settings...
                       => Macro Settings


The only option that will allow the macro to run automatically:

Enable all macros (not recommended; potentially dangerous code can run)


Pay attention to the warning.



All Articles