Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:58:13+00:00 2026-05-25T05:58:13+00:00

In my C# application, I can Open a new Excel process by clicking a

  • 0

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).

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 :

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 && (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(); 
}

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…

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?

Edit : Ok,

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).

It’s not what I really wanted to do, but it solve my problem…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:58:13+00:00Added an answer on May 25, 2026 at 5:58 am

    I would suggest utilizing the Excel COM model rather than running the process by hand. You can subscribe to events of the Worksheet and close the application.

    These MSDN documents might be helpful:

    http://msdn.microsoft.com/en-us/library/wss56bz7(v=vs.80).aspx

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.worksheet_members.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application i can import csv file but i have data in excel
I have a Windows Forms (.NET) application that can have multiple documents open simultaneously.
On Gnome/KDE you can select in which application you want to open file (Right
I have: Public Class ExcelProcess Private App As New Excel.Application Private Books As Excel.Workbooks
I have a desktop application using vb.net, to process some excel files, those files
Code # get already active Excel application or open new my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
I have a Application on which i'm uploading a Excel File and displaying the
I need open source database that I can ship with my commercial application. It
Do you know what can I use to open page in my application and
I need to make so that my application can have only one instance running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.