none
Word.ApplicationClass WordApp = new Word.ApplicationClass();, whether it fails if MS office is installed in another location than normal? RRS feed

  • Question

  • I have a c# applicaiton( a service application that runs in  the backgrnd). It checks/ensures whether MS word( MS office is installed or not, correct needed version)
    Main point to note here is , MS office is installed in other location than normal.

    try
    {
     WordApp = new Word.ApplicationClass();
    }
    catch
    {
     bIsMSOfficeAvailable = false;
    }
     wordVersion = WordApp.Version;
     
        
    The above code fails for us and reports an user defined error saying, MS office is required.
    All is perfectly fine whe Office is installed in normal location. My question here is Word.ApplicationClass() fails for the same reason? Does it expects to be instaled in normal location? How does it see the word application installed?

    • Moved by Just Karl Monday, September 23, 2013 2:34 PM Was in the off-topic forum.
    Monday, September 23, 2013 9:44 AM

Answers

  • Have no idea.

    But I recommend you use Application instead of ApplicationClass.

    The code below works fine for me, you can try this way:

    static void GetWordVersion()
            {
                string sVersion = string.Empty;
                Microsoft.Office.Interop.Word.Application Wordapp = new Microsoft.Office.Interop.Word.Application();
                switch (Wordapp.Version.ToString())
                {
                    case "7.0":
                        sVersion = "95";
                        break;
                    case "8.0":
                        sVersion = "97";
                        break;
                    case "9.0":
                        sVersion = "2000";
                        break;
                    case "10.0":
                        sVersion = "2002";
                        break;
                    case "11.0":
                        sVersion = "2003";
                        break;
                    case "12.0":
                        sVersion = "2007";
                        break;
                    case "14.0":
                        sVersion = "2010";
                        break;
                    case "15.0":
                        sVersion = "2013";
                        break;
                    default:
                        sVersion = "Too Old!";
                        break;
                }
                Console.WriteLine("MS office version: " + sVersion);
                Wordapp.Quit();
            }
    Tuesday, September 24, 2013 9:41 AM

All replies

  • Have no idea.

    But I recommend you use Application instead of ApplicationClass.

    The code below works fine for me, you can try this way:

    static void GetWordVersion()
            {
                string sVersion = string.Empty;
                Microsoft.Office.Interop.Word.Application Wordapp = new Microsoft.Office.Interop.Word.Application();
                switch (Wordapp.Version.ToString())
                {
                    case "7.0":
                        sVersion = "95";
                        break;
                    case "8.0":
                        sVersion = "97";
                        break;
                    case "9.0":
                        sVersion = "2000";
                        break;
                    case "10.0":
                        sVersion = "2002";
                        break;
                    case "11.0":
                        sVersion = "2003";
                        break;
                    case "12.0":
                        sVersion = "2007";
                        break;
                    case "14.0":
                        sVersion = "2010";
                        break;
                    case "15.0":
                        sVersion = "2013";
                        break;
                    default:
                        sVersion = "Too Old!";
                        break;
                }
                Console.WriteLine("MS office version: " + sVersion);
                Wordapp.Quit();
            }
    Tuesday, September 24, 2013 9:41 AM
  • If your main purpose is to determine whether Office is installed I don't think starting a new instance of any Office application is an optimal way to determine this. It would make more sense to search the Registry for relevant entries.

    Cindy Meister, VSTO/Word MVP, my blog

    Monday, September 30, 2013 6:34 PM
    Moderator