Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

Word 2013- VBA -Accept All Changes In Selection

I am trying to create a macro to accept all changes in a selection. I used the macro recorder and it generated the following code below (it can also be found at https://docs.microsoft.com/en-us/office/vba/api/word.revisions.acceptall)

Selection.Range.Revisions.AcceptAll

However, if I run the macro, it will not work unless I physically select each letter

enter image description here

enter image description here

But if I use the built in buttons in the 'Changes' group within the 'Review' tab, I don't have to physically select the entire letter. I just need to select any part of the change and it will accept the change.

enter image description here

enter image description here

Why does the macro version not perform like the UI option?

question from:https://stackoverflow.com/questions/65851256/word-2013-vba-accept-all-changes-in-selection

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That is odd behavior. The UI must be doing something like the below, but whoever built the macro recorder missed it.

Public Sub AcceptSelection()
    
    Dim rev As Revision
    
    For Each rev In Selection.Range.Revisions
        rev.Accept
    Next rev
    
End Sub

That code will accept any revisions in the selection, even partial ones.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...