i have a small application developed in C# .NET
that manipulate excel sheets, I don't know why some users keep telling me that when they open the excel file the window doesn't appear on front/top although I set the visible to true and the window state on maximized.
This is the function that reads the excel file:
public static void OpenExcel(string fileName, bool visibility, FunctionToExecute fn = null)
{
string addInPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft\\AddIns\\mDF_XLcalendar.xla");
deleg = fn;
app = new Excel.Application();
app.Workbooks.Open(addInPath);
app.Workbooks.Open(fileName);
app.ScreenUpdating = true;
app.DisplayAlerts = true;
app.Visible = visibility;
app.UserControl = true;
app.WindowState = Excel.XlWindowState.xlMaximized;
EventDel_BeforeBookClose = new Excel.AppEvents_WorkbookBeforeCloseEventHandler(application_WorkbookBeforeClose);
EventSave_BeforeBookClose = new Excel.AppEvents_WorkbookBeforeSaveEventHandler(Open_ExcelApp_WorkbookBeforeSave);
app.WorkbookBeforeClose += EventDel_BeforeBookClose;
app.WorkbookBeforeSave += EventSave_BeforeBookClose;
}
Any ideas ?
I would try to activate the excel window by
If this doesn't work you might find other solutions (involving Native WinAPI calls) at this thread at http://social.msdn.microsoft.com/
Sometimes if there is more than one file open at same time in Excel,
ActiveWindow.Activate()
will not work.A successful trick is to do minimize then maximize commands.
To activate a specific workbook:
some magic, that work for me:
I found this to work. How to bring an Excel app to the front
A little late I know, but why the need to use FindWindow, the Windows handle is accessible via the Application :
There will be no problems if more than one window has the same caption.