Tuesday, September 22, 2009

Getting Word from Running Object Table (ROT) using C#

Usually in Word Automation, we need to ensure that only one instance of word application is running. This is can be achieved by getting the word application from ROT and use it. Below is the code which does this functionality


Word.Application objApplication;

                try
                {
                    objApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") as Word.Application;
                   
                   
                }
                catch
                {
                    objApplication = new Microsoft.Office.Interop.Word.Application();
                }



This code can be used for any application which is hosted in ROT.

No comments:

Post a Comment