none
Speed Up Populating Bookmark? RRS feed

  • Question

  • Is there another way to speed up loading the bookmarks w/o making the application.visible = false? It is alot fast, but can't have the application going invisible.

     

    VSTO .Net 4

    Word 2010 Document

    Friday, November 4, 2011 2:56 PM

Answers

  • Hi "Bull"

    Right... I was sort of hoping your code would be using GoTo and Selection, because then I could have speeded things up and looked like a real hero... <sigh>

    Using the object model, I don't see any way to speed things up. No idea why making the doc invisible would make it that much faster. The one thing you could try is:
    this.Application.ScreenUpdating = false (resetting to true when you're done). I'm not optimistic, but you never know...

    Other than that, we'd have to look at alternate approaches. In that case, my first question would be: are you actually using form fields, not just bookmarks? (I ask because of Protect/Unprotect.) If yes, do you expect the user to edit the information in the form fields?

    If form fields aren't playing a part in this, I can imagine some other approaches. But to make meaningful suggestions it would help to understand the "work flow" behind this (when the user is involved, mostly). Also, the version of Word involved could be critical.


    Cindy Meister, VSTO/Word MVP
    Monday, November 14, 2011 5:54 PM
    Moderator
  • Hi Ray

    Yes, please show us the code you're using...


    Cindy Meister, VSTO/Word MVP
    Friday, November 11, 2011 7:53 AM
    Moderator

All replies

  • Hi RowdyBullGaming,

     

    Thanks for posting in the MSDN forum.

     

    Dose you want to speed up loading the bookmarks without making the application.visible = false?

    I don’t know the dimension that you use to balance the loading speed. And I think set application.visible = false will not affect the time to loading book mark.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, November 7, 2011 7:29 AM
    Moderator
  • Hi "Bull"

    Please provide more information about what you mean by "loading the bookmarks". I'm guessing you mean you're writing information to the bookmarks when a document opens or is created? Could you describe the scenario in a bit more detail, please? Including the code involved.


    Cindy Meister, VSTO/Word MVP
    Tuesday, November 8, 2011 11:03 AM
    Moderator
  • Hi RowdyBullGaming,
     
    Any update?
     
    Tom

    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 10, 2011 9:35 AM
    Moderator
  • Oh wow I apologize!

    It is pretty simple I have a user control in wpf that you select a record and it loops through and updates each bookmarks .Text property to the value from the object I pass into the UpdateBookmarks Method I created. We are talking about like 20 bookmarks it is taking like 10-11 secs to execute. If I set the application.Visible to False before the update and to True after it takes about 4 seconds, but the Window Disappearing is not acceptable.

    Thanks,

    Ray

    Thursday, November 10, 2011 6:32 PM
  • Hi Ray

    Yes, please show us the code you're using...


    Cindy Meister, VSTO/Word MVP
    Friday, November 11, 2011 7:53 AM
    Moderator
  • Here it is... Sorry didn't have access over the weekend.

     

    public void UpdateBookmarks(V_MailMerge_Summary mail)
            {
                try
                {
                    Unlock();
    
                    this.bmLast.Text = mail.last;
                    this.bmFirst.Text = mail.first;
                    this.bmMiddle.Text = mail.middle;
                    this.bmId.Text = mail.id_.ToString();
                    this.bmDOB.Text = mail.dob;
                    this.bmContactFirst.Text = mail.ContactFirstName;
                    this.bmContactLast.Text = mail.ContactLastName;
                    this.bmRelation.Text = mail.Relationship;
                    if (mail.Relationship != null)
                    {
                        if (mail.Relationship.Length >= 12)
                        {
                            this.bmRelation.Range.Font.Size = (float)7.5;
                        }
                    }
                    this.bmPhoneDay1.Text = mail.Phone;
                    this.bmPhoneNight1.Text = mail.EveningPhone;
                    this.bmCell1.Text = mail.CellPhone;
                    this.bmPhoneDay2.Text = mail.Phone;
                    this.bmPhoneNight2.Text = mail.EveningPhone;
                    this.bmCell2.Text = mail.CellPhone;
                    this.bmPrimary.Text = mail.Primary;
                    if (mail.Primary != null)
                    {
                        if (mail.Primary.Length >= 33)
                        {
                            this.bmPrimary.Range.Font.Size = 6;
                        }
                    }
                    this.bmSecondary.Text = mail.Secondary;
                    if(mail.Secondary != null)
                    {
                        if (mail.Secondary.Length >= 35)
                        {
                            this.bmSecondary.Range.Font.Size = 6;
                        }
                    }
                    
    
                    Lock(true);
    
                }
    
                catch (Exception ex)
                {
                    new HandleException(ex);
                    return;
                }
            }
    
    
            private void Lock(bool fillInForm = false)
            {
                if (fillInForm == true)
                {
                    doc.Protect(WdProtectionType.wdAllowOnlyFormFields, NoReset: false, Password: "123456");
                }
                else
                {
                    doc.Protect(WdProtectionType.wdAllowOnlyReading, NoReset: false, Password: "123456");
                }
            }
    
           
    
            private void Unlock()
            {
                doc.Unprotect("123456");
            }
    


     

    Monday, November 14, 2011 2:36 PM
  • Hi "Bull"

    Right... I was sort of hoping your code would be using GoTo and Selection, because then I could have speeded things up and looked like a real hero... <sigh>

    Using the object model, I don't see any way to speed things up. No idea why making the doc invisible would make it that much faster. The one thing you could try is:
    this.Application.ScreenUpdating = false (resetting to true when you're done). I'm not optimistic, but you never know...

    Other than that, we'd have to look at alternate approaches. In that case, my first question would be: are you actually using form fields, not just bookmarks? (I ask because of Protect/Unprotect.) If yes, do you expect the user to edit the information in the form fields?

    If form fields aren't playing a part in this, I can imagine some other approaches. But to make meaningful suggestions it would help to understand the "work flow" behind this (when the user is involved, mostly). Also, the version of Word involved could be critical.


    Cindy Meister, VSTO/Word MVP
    Monday, November 14, 2011 5:54 PM
    Moderator
  • You are a Hero! The .ScreenUpdating = false is really speeding this thing up. Loads in about 3 secs... That worked out great.

    The document does mix form fields and bookmarks. I am only updating the bookmarks. the fields are for user added manual data! Thank Again.

    Monday, November 14, 2011 7:07 PM