none
Loading MS Word without addins in C# RRS feed

  • Question

  • Hi All,

    I wish to load Word Application without addins for purpose of previewing a document. This will help  in getting the Word Application up faster .

    I am currently using the following code

            public Word.Application GetWordInstanceWithoutAddins()

            {

                Word.Application objWordApp;

                Process proc = new Process();

                proc.StartInfo.FileName ="winword.exe";

                proc.StartInfo.Arguments = "/a";

                proc.StartInfo.CreateNoWindow = true;

                proc.Start();

                proc.Close();

                int retries = 0;

                while (true)

                {

                    try

                    {

                        if (Process.GetProcessesByName("winword").GetLength(0) > 0)

                        {

                            objWordApp = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");

                            break;

                        }

                    }

                    catch { System.Threading.Thread.Sleep(500); }

                    if (retries > 5)

                    {

                        objWordApp = new Microsoft.Office.Interop.Word.Application();

                        break;

                    }

                    retries++;

                }

                objWordApp.Visible = false;

                objWordApp  = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");

                return objWordApp;

            }

    Posting this query in case there is a more elegant method.


    Thanks

    Tomy



    Wednesday, August 28, 2013 11:24 AM

All replies

  • Thank you for your sharing.

    But this forum is talking about VBA, it seems you are using C#, I think you post in wrong forum.

    Tuesday, October 8, 2013 3:28 AM