Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad Excel process and close the entire process when closing a document
    primarykey
    data
    text
    <p>In my C# application, I can Open a new Excel process by clicking a button. Then, it waits for input idle and load a new Excel file. I have to accomplish it because I want all macros and tools to be loaded before loading my document (otherwise, there is a rendering bug).</p> <p>The Process Id is saved in a var, and when I click again on that button, with the PID, if the process already exists, the Process has the focus, otherwise, a new process is created : </p> <pre><code>Process processExcel = null; if (pId_m.HasValue) { try { processExcel = Process.GetProcessById(pId_m.Value); } catch (Exception ex) { Log.MonitoringLogger.Error("Unable to find Pid : " + pId_m,ex); } } if (processExcel != null &amp;&amp; (processExcel.HasExited == false)) { AutomationElement element = AutomationElement.FromHandle(processExcel.MainWindowHandle); if (element != null) { element.SetFocus(); } } else { ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "Excel.exe"; info.Arguments = " /e "; processExcel_l = Process.Start(info); pId_m = processExcel_l.Id; processExcel_l.WaitForInputIdle(); processExcel_l.StartInfo = new ProcessStartInfo(path); processExcel_l.Start(); } </code></pre> <p>The problem is the following : when I close the Excel document window (and not Excel window), and I click the button, the focus is set to the Excel process, but without any document... This behavior is logic, but not working for what I want...</p> <p>I have seen a software that load a new process and a new document inside, but when clicking on the document close button, the entire process was exited... How to reproduce the same?</p> <p><strong>Edit</strong> : Ok,</p> <p>Finally instead of setting the focus on the process, I launched a file on this process (which set focus if the file is already open).</p> <p>It's not what I really wanted to do, but it solve my problem...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload