Hide Excel 2013 while programmatic change a workbook

此生再无相见时 提交于 2019-12-06 03:06:33

In my Excel 2013, using excelApp = new Excel.Application doesn't show any window.

May it be some VBA code in opened workbook which displays window?

So I know the question is old but I needed an answer and none of the given ones worked for me. I ended up just setting Visible to false when initializing to avoid the window flashing open before hiding.

Excel.Application excelApp = new Excel.Application() { Visible = false };

Hide Excel application your code has launched, before opening any Workbook :

Excel.Application excel = new Excel.Application();
excel.Visible = false;
[...]
Excel.Workbook workbook;
workbook = excel.Workbooks.Open(...);

You should always put the Visible into try/catch-block

Excel.Application xlsApp = new Excel.Application();
try
{
     // Must be surrounded by try catch to work.
     // http://naimishpandya.wordpress.com/2010/12/31/hide-power-point-application-window-in-net-office-automation/
     xlsApp.Visible = false;
     xlsApp.DisplayAlerts = false;
}
catch (Exception e)
{
     Console.WriteLine("-------Error hiding the application-------");
     Console.WriteLine("Occured error might be: " + e.StackTrace);
}
 Excel.Workbook workbook;
 workbook = xlsApp.Workbooks.Open(File, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!