none
Selection highlighting is removed while working with range.Revisions object. RRS feed

  • Question

  • I am facing the selection issue while working with range.Revisions. I am able to reproduce it on Word 2013 document using the following steps.

    • Create a new word document.
    • Create a macro like the following
     Sub RevisionsRangeSelectionDrawingIssue()
        Dim rng As Range
        Set rng = Selection.Range.Duplicate
        For Each myRev In rng.Revisions
        Next myRev
    End Sub
    • Write text “test”
    • Select “test”
    • Run the macro

     

    Actual result: The selection is removed from the word. If we apply any attributes to it they gets applied and selection is restored

    Desired Result: The selection should not be removed from the word.

    I my code I need to check for revisions whenever selection takes place. I want to know if anyone else faced the same issue and do we have any workaround for the same.

    • Edited by VinayVerma Monday, February 24, 2014 12:02 PM updated
    • Moved by Tony Chen CHN Tuesday, February 25, 2014 3:58 PM Word dev
    Monday, February 24, 2014 11:56 AM

Answers

  • Hi Vinay

    In the meantime, I've had confirmation of a repro based on your steps - thank you.

    As mentioned in my previous reply, the way to work around this is to use a command that forces screen redrawing, such as ScreenRefresh or changing the Zoom factor.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by VinayVerma Thursday, February 27, 2014 1:21 PM
    Wednesday, February 26, 2014 7:29 AM
    Moderator
  • Thanks Cindy,

                          As ScreenRefresh can be fairily expensive opration in itself so I will go for "Application.screenUpdating = false"  instead. So now macro will become

    Sub RevisionsRangeSelectionDrawingIssue()
    '
    ' RevisionsRangeSelectionDrawingIssue Macro
    '
        Dim rng As Range
        Set rng = Selection.Range.Duplicate
        
        Dim screenUpdating As Boolean
        screenUpdating = Application.screenUpdating
        
        If (screenUpdating) Then
            Application.screenUpdating = False
        End If
        
        For Each myRev In rng.Revisions
        Next myRev
        
        If (screenUpdating) Then
            Application.screenUpdating = True
        End If
        
    End Sub 

    <o:p>-Vinay</o:p>


    • Edited by VinayVerma Thursday, February 27, 2014 10:30 AM Typo
    • Marked as answer by VinayVerma Thursday, February 27, 2014 1:21 PM
    Thursday, February 27, 2014 10:29 AM

All replies

  • Others have reported similar

    http://social.msdn.microsoft.com/Forums/office/en-US/1b1bbd7c-491a-47e3-bbdb-d7378ffe10dd/the-select-range-disappear-in-catched-copy-event?forum=worddev

    http://social.msdn.microsoft.com/Forums/office/en-US/b44e4134-7e99-4ea7-8b6a-76d39b121007/selection-highlighting-disappears?forum=worddev

    In all cases, the problem isn't reproducible in test environments used by forum moderators/MS Support. The one thread found that using Application.ScreenRefresh would get the Selection marking back.

    Could you please provide information on the OS your code is running on and whether you're using JAWS (and if yes, which version)?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, February 25, 2014 6:07 PM
    Moderator
  • Hi Vinay,

    I failed to reproduce the issue in Office 2013 + Windows 8.1. Actually If I click the VBE to run the macro the background of selection will disappear but the selection isn’t removed. It will highlight again when you click the word document.
    Also I change the macro to below to check it:

    Sub RevisionsRangeSelectionDrawingIssue()
    Debug.Print "Selection Text before running Macro:" & Selection.Range.Text
        Dim rng As Range
        Set rng = Selection.Range.Duplicate
        For Each myRev In rng.Revisions
        Next myRev
    Debug.Print "Selection Text after running Macro:" & Selection.Range.Text
    End Sub

    Screen Shot:
     
    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.


    Wednesday, February 26, 2014 3:28 AM
    Moderator
  • Hi Vinay

    In the meantime, I've had confirmation of a repro based on your steps - thank you.

    As mentioned in my previous reply, the way to work around this is to use a command that forces screen redrawing, such as ScreenRefresh or changing the Zoom factor.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by VinayVerma Thursday, February 27, 2014 1:21 PM
    Wednesday, February 26, 2014 7:29 AM
    Moderator
  • Thanks Cindy,

                          As ScreenRefresh can be fairily expensive opration in itself so I will go for "Application.screenUpdating = false"  instead. So now macro will become

    Sub RevisionsRangeSelectionDrawingIssue()
    '
    ' RevisionsRangeSelectionDrawingIssue Macro
    '
        Dim rng As Range
        Set rng = Selection.Range.Duplicate
        
        Dim screenUpdating As Boolean
        screenUpdating = Application.screenUpdating
        
        If (screenUpdating) Then
            Application.screenUpdating = False
        End If
        
        For Each myRev In rng.Revisions
        Next myRev
        
        If (screenUpdating) Then
            Application.screenUpdating = True
        End If
        
    End Sub 

    <o:p>-Vinay</o:p>


    • Edited by VinayVerma Thursday, February 27, 2014 10:30 AM Typo
    • Marked as answer by VinayVerma Thursday, February 27, 2014 1:21 PM
    Thursday, February 27, 2014 10:29 AM
  • Hi Fei,

             I never said that selection is removed. I said that "Selection Highlighting" is removed. Yes it is a drawing issue. I am able to find a decent workaround for the same.

    Thanks for your help.

    -Vinay

    Thursday, February 27, 2014 10:38 AM
  • Was this issue ever patched?
    Thursday, October 12, 2017 1:38 PM