How to force personal.xls workbook to open when Excel starts using Automation?

I realized that when Excel is opened using automation, it does not open its launch items by default, such as the personal.xls workbook. This causes problems for my users, who sometimes open Excel through my application and then continue to use it for further work.

Unfortunately, the Excel instance opened this way does not contain its own macros. They have to close Excel and reopen it from outside my application for their macros to be available.

Is there a way to get Excel to automatically load the personal.xls workbook on startup via automation? If not, what would be the best way to open this file, given that it should not be visible to the user but remain hidden?

I didn't find any options for this when creating an object and opening the app

Excel.Application xlApp = new Excel.Application();

      

Any advice or links anyone can provide would be most appreciated. I've searched and searched for information on this, but no one seems to have tried to get around this. I am using Excel 2007 and .NET 2.0.

+3


source to share


2 answers


It turns out that simply finding and opening the user personal.xls (or personal.xlsx for those created in newer versions of Excel) is the answer.

Excel.Application xlApp = new Excel.Application();
string filename = xlApp.StartupPath + "\\personal.xls";

xlApp.Workbooks.Open(filename, 0, false, 5, Missing.Value, Missing.Value, false,
    Missing.Value, Missing.Value, Missing.Value, false, Missing.Value, false,
    true, false);

      



The personal.xls workbook opens hidden in the background (as needed) and allows full use of all macros attached to it.

Once I knew what to look for, I found some good information in this post: Excel XLSTART problem with C # /. Net

+2


source


I don't know if this is what you are looking for, but I had the same problem adding to Word. I solved it, but it might not be what you want.

Save the file with automation, then run it using the process.



System.Diagnostics.Process.Start("excel.exe", "C:\\somefolder\\somefolder\\personal.xls");

      

Hope this works.

0


source







All Articles