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 195491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:41:12+00:00 2026-05-11T16:41:12+00:00

I’m writing an automated test to determine whether or not rtf files are successfully

  • 0

I’m writing an automated test to determine whether or not rtf files are successfully opened by MS Word. So far I looping through all the rtfs within a given directory and opening them. Later I will have to catch exceptions to generate a report (log the file name that crashed word).

I am processing a large number of files. My application is currently opening a new instance of Word for each file. Can someone tell me how to close Word?

public class LoadRTFDoc
{
    private object FileName;
    private object ReadOnly;
    private object isVisible;
    private object Missing;
    private ApplicationClass WordApp;
    private object Save;
    private object OrigFormat;
    private object RouteDoc;

    public LoadRTFDoc(object filename)
    {
        this.WordApp = new ApplicationClass();
        this.FileName = filename;
        ReadOnly = false;
        isVisible = true;
        Missing = System.Reflection.Missing.Value;
        Save = System.Reflection.Missing.Value;
        OrigFormat = System.Reflection.Missing.Value;
        RouteDoc = System.Reflection.Missing.Value;

    }


    public void OpenDocument()
    {
        WordApp.Visible = true;
        WordApp.Documents.Open(ref FileName, ref Missing, ref ReadOnly, ref Missing, ref Missing,
                                   ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
                                   ref isVisible, ref Missing, ref Missing, ref Missing, ref Missing);
        WordApp.Activate();
    }
    public void CloseDocument()
    {
        WordApp.Documents.Close(ref Save, ref OrigFormat, ref RouteDoc);
    }

}

I am executing the CloseDocument() method after each document is opened. Anyone have some insight for me on this?

  • 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-11T16:41:12+00:00Added an answer on May 11, 2026 at 4:41 pm
    WordApp.Quit() 
    

    will exit the application.

    However, the safest way is to get a handle to the process and kill the winword process. In C# the following code would do that:

    foreach (Process p in Process.GetProcessesByName("winword"))
    {
        if (!p.HasExited)
        {
            p.Kill();
        }
    }
    

    The reason is that it will happen frequently (I assume, especially since you are testing documents created not by Word) that Word will hang with an open message box, e.g. a repair dialog. In that case killing the process is the easiest way to close the application.

    I would suggest that you first try to close Word using Application.Quit. If this does not work it indicates a problem with your input file (most likely because a repair dialog is blocking Word). You should record this as an error in your log and then proceed killing the winword process.

    Another problem you might face is Word’s document recovery feature blocking the application on startup (and thus preventing a document from being opened until the recovery dialog box is clicked away). Document recovery can be disabled by deleting the following registry key under both HKCU and HKLM prior to starting Word (replace 12.0 with 11.0 for Word 2003 and 10.0 for Word XP):

    Software\Microsoft\Office\12.0\Word\Resiliency
    

    It goes without saying that killing Word is a rather rude approach, however, it is simple and rather robust. The code above will just kill any instance of Word for a user. If you want to kill only a specific instance things get more difficult. You would have to retrieve the process id of a specific Word instance. Typically this can be done by searching for the window title of the instance, e.g. using WinAPI functions like FindWindowByCaption and GetWindowThreadProcessId.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I need to clean up various Word 'smart' characters in user input, including but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I need a function that will clean a strings' special characters. I do NOT

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.