none
ScreenUpdating does not work in Word RRS feed

  • Question

  • Hello,

    I am using VSTO to program an Office 2007 Add-in. This is my code:

    WordApp.ScreenUpdating = false;
    WordApp.Selection.EndKey(ref unit, ref miss);

    The Selection goes to the end of the document. However, i can still see this on screen. I would have expected that with ScreenUpdating = false, the user will not see this on the screen and will only be done 'silently'. Is my understanding of ScreenUpdating correct? If so, why does it not work?

     

    Thanks

     


    • Edited by Steve454889 Tuesday, December 6, 2011 5:12 PM
    Tuesday, December 6, 2011 5:12 PM

Answers

  • Hi Steve

    Your understanding of ScreenUpdating is NOT correct, I'm afraid. This only suppresses some actions taken during code interaction with the object model. It can help increase performance and reduce screen "flicker", but it won't suppress all actions.

    But the better approach in most cases is to work with a RANGE rather than the Selection object.

    One way (of many) to define a Range at the end of the document (in order to add text, for example):

    Word.Range rng = theDocument.Content;
    object collapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
    rng.Collapse(ref collapseEnd);
    rng.Text = "some text at the end of the document";


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Steve454889 Thursday, December 8, 2011 9:26 AM
    Tuesday, December 6, 2011 8:44 PM
    Moderator

All replies

  • Hi Steve

    Your understanding of ScreenUpdating is NOT correct, I'm afraid. This only suppresses some actions taken during code interaction with the object model. It can help increase performance and reduce screen "flicker", but it won't suppress all actions.

    But the better approach in most cases is to work with a RANGE rather than the Selection object.

    One way (of many) to define a Range at the end of the document (in order to add text, for example):

    Word.Range rng = theDocument.Content;
    object collapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
    rng.Collapse(ref collapseEnd);
    rng.Text = "some text at the end of the document";


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Steve454889 Thursday, December 8, 2011 9:26 AM
    Tuesday, December 6, 2011 8:44 PM
    Moderator
  • The ScreenUpdating is very frustrating as it is not consistent as Cindy states, it does work but there are some areas like swapping regions and headers and footers that still show up in the user interface, I have mentioned this a number of times and it falls on deaf ears to be honest due to the size of the object model.

    Regards


    Mike Walker MVP - Visual Developer VSTO 2004-2010 Please mark the best replies as Answers Twitter: www.twitter.com/mikewalker74
    Wednesday, December 7, 2011 11:36 AM
    Moderator
  • Thanks for clarifying this Cindy. I believe using the Selection object was my mistake. I will try to use the Range object instead!

    Thursday, December 8, 2011 9:28 AM