none
Control document position in active window RRS feed

  • Question

  • Hi

    In one of my customers COM Addins för Word 2010, we have some code running in the DocumentBeforeSave event in order to verify some content in the document. This event is also triggered when Autosave kicks in.

    To make sure the document position within the ActiveWindow is not changed in this process, we have used the <document>.ActiveWindows.VerticalPercentScrolled value to get before and reset after our check is done.

    This works fairly well with smaller documents, since the value you get is a percentage och the whole document.
    But the larger the document get, the less accurate is this approach.
    The document can shift half a page up or down, which is not appreciated by the users.Does anyone know of a better way to make the document position remain the same during saves?


    Best Regards Peter Karlström Midrange AB, Sweden

    Wednesday, October 22, 2014 2:39 PM

Answers

  • Seems there are no way of beeing as exact as I hoped.


    Best Regards Peter Karlström Midrange AB, Sweden

    Friday, November 7, 2014 1:28 PM

All replies

  • Hi Peter,

    Based on the description, you want to keep the document position not changing. However, I am not able to under the scenario exactly. Did you change the content of the document? Because if the content of document is not changing, the reset the verticalpersent should work.

    In addition, does it work for you that insert a bookmark to keep the position you want to keep and use Selection.Goto to move the insert position or the original one?

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 23, 2014 6:23 AM
    Moderator
  • Hello

    Thanks for your reply

    I know what you mean, but the verticalprocentscrolled is not exact enough for large documents.
    You can test this if you have a mouse with scroll-wheel and scrolls the document with only the wheel.

    For a small document, the scrollbar marker moves for every "click" in the mouse wheel.
    For a large document, you will have to make more than 1 "click" in order to move the scrollbar marker.
    And the Verticalprocentscrolled is the scrollmarker here, not the mouse  "clicks".

    Also, we can't be sure that Selection is on the page we see. Selection is where your caret is which can be on a page far away.


    Best Regards Peter Karlström Midrange AB, Sweden

    Thursday, October 23, 2014 6:38 AM
  • Hi Peter,

    >> Does anyone know of a better way to make the document position remain the same during saves?

    How about using the line number? Instead of using Selection.GoTo method, I think you could consider using Document.GoTo method.

                // get the line number before document close
                var lineNum = Globals.ThisDocument.Application.Selection.get_Information(WdInformation.wdFirstCharacterLineNumber);
    
    
                // go the range and select when opening the docuemnt next time.
                var rng = Globals.ThisDocument.Application.ActiveDocument.GoTo(What: WdGoToItem.wdGoToLine, Which: WdGoToDirection.wdGoToAbsolute, Count: 100 /* line number */);
    
                rng.Select();

    Hope it will help.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 24, 2014 2:18 AM
    Moderator
  • Hello Jeffrey

    Thanks for your reply.

    As I mentioned we really can't be sure the caret will be placed on the visible part of the document, so we can't use Range and Selection.Information as means to determine document position.

    Thanks anyway


    Best Regards Peter Karlström Midrange AB, Sweden

    Friday, October 24, 2014 6:15 AM
  • Seems there are no way of beeing as exact as I hoped.


    Best Regards Peter Karlström Midrange AB, Sweden

    Friday, November 7, 2014 1:28 PM