CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2021
    Posts
    51

    How to kill Excel process?

    Hi,
    I'm doing an action in first debug like this:
    1, Create excel instance.
    2, During debugging, turn it off suddenly.
    In some case, this processes still run in background,
    so when i use getobject code get the instance but now they are no longer valid.

    I used the following code in second debug but it doesn't work?

    //check [getobject] if catch error then terminate process and create new one:
    ::PostMessage(hWnd, WM_CLOSE, 0, 0);

    How do I kill this process?

    Name:  bug1.png
Views: 426
Size:  13.8 KB

    Thanks you!
    Last edited by Dang.D.Khanh; July 19th, 2021 at 04:38 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to kill Excel process?

    How do you obtain the window handle (hWnd)?
    If this handle is not valid or the window does not exist then the only way "to kill" is to call TerminateProcess. However, you need to know the process handle of the Excel process.
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2021
    Posts
    51

    Re: How to kill Excel process?

    Thanks Sir,
    I'm trying your suggestion.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to kill Excel process?

    1, Create excel instance.
    How do you create the Excel instance? Do you use CreateProcess? Are you loading it as a COM server using COM?

  5. #5
    Join Date
    Jun 2021
    Posts
    51

    Re: How to kill Excel process?

    Quote Originally Posted by Arjay View Post
    How do you create the Excel instance? Do you use CreateProcess? Are you loading it as a COM server using COM?
    Hi Sir,
    I'm using CreateInstance function from automate.
    I'm still investigating it. for the time being, I will monitor taskmanager and end this task manually if I get this case.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to kill Excel process?

    Quote Originally Posted by Dang.D.Khanh View Post
    Hi Sir,
    I'm using CreateInstance function from automate.
    I'm still investigating it. for the time being, I will monitor taskmanager and end this task manually if I get this case.
    Could you provide some code snippets with "using CreateInstance" and so on?

    And the same - for your "close procedure".
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2021
    Posts
    51

    Re: How to kill Excel process?

    Quote Originally Posted by VictorN View Post
    Could you provide some code snippets with "using CreateInstance" and so on?

    And the same - for your "close procedure".
    I'm using the code from this post,
    From old posts I see it's name is CreateDispatch but when I use it I see only name CreateInstance.

    I'm trying this answer, it might help me
    Last edited by Dang.D.Khanh; August 16th, 2021 at 11:58 AM.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to kill Excel process?

    Quote Originally Posted by Dang.D.Khanh View Post
    I'm using the code from this post,
    From old posts I see it's name is CreateDispatch but when I use it I see only name CreateInstance.

    I'm trying this answer, it might help me
    Try calling Quit.

  9. #9
    Join Date
    Jun 2021
    Posts
    51

    Re: How to kill Excel process?

    Quote Originally Posted by Arjay View Post
    Try calling Quit.
    Thanks sir, I think it is a solution that works in most cases.
    my problem is solved .

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured