How to know when a word document has finished loading all pages RRS feed

  • Question

  • Hi,

    I have a large mail merged document (270 pages). i have customized the ribbon and there is a new print button. when i click on that button, when the document is still loading, it errors. I wanted to know how to write a code to check whether the word document has finished loading all the pages.



    Friday, September 20, 2013 3:38 PM


  • Hi Charul,

    As far as I know, we can use WindowActivate event to check if word finished loading the

    document. You can enable or disable your Print button as applicable depending on which

    document was activated. If you customized the ribbon in VSTO . we can disable print button

    when document is opened and enable print button when the document is active.

    In Ribbon Class

            public bool SetPrintButtonEnable
                    if (this.PrintButton.Enabled != value)
                        this.PrintButton.Enabled = value; 

    In Add-in Class add DocumentOpen and WindowActivate event handler to enable/disable print button.

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
                this.Application.DocumentOpen += Application_DocumentOpen;
                this.Application.WindowActivate += Application_WindowActivate;
            void Application_WindowActivate(Word.Document Doc, Word.Window Wn)
                Globals.Ribbons.Ribbon1.SetPrintButtonEnable =true ;
            void Application_DocumentOpen(Word.Document Doc)
                Globals.Ribbons.Ribbon1.SetPrintButtonEnable = false ;

    Please refer to the following link to get more information.

    #Application.WindowActivate Event (Word)

    #Application.DocumentOpen Event(Word)

    Thanks & Regards

    Wednesday, September 25, 2013 7:14 AM