MS Word macro to manipulate tracked text
Thread poster: Samuel Murray
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 20:10
Member (2006)
English to Afrikaans
+ ...
Oct 20, 2016

Hello everyone

Does anyone know of a macro that will modify a tracked changes document in MS Word so that it adds curly brackets on either side of a deletion and square brackets on either side of an insertion?

It doesn't matter to me if the brackets close whole chunks of deletions or insertions, or deleted or inserted characters individually, nor does it matter to me if the tracks remain intact and/or if the brackets are tracked.

Here are two examples of wh
... See more
Hello everyone

Does anyone know of a macro that will modify a tracked changes document in MS Word so that it adds curly brackets on either side of a deletion and square brackets on either side of an insertion?

It doesn't matter to me if the brackets close whole chunks of deletions or insertions, or deleted or inserted characters individually, nor does it matter to me if the tracks remain intact and/or if the brackets are tracked.

Here are two examples of what I'm looking for (any of the 6 options shown under the example would be acceptable to me, though I would prefer the third one, i.e. nothing in tracks anymore, and whole tracked sections bracketed):

track example1

track example2

I need this so that I can add tracked text to my TM.

Thanks
Samuel



[Edited at 2016-10-20 14:21 GMT]

[Edited at 2016-10-20 14:23 GMT]
Collapse


 
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 20:10
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
One option Oct 20, 2016

Samuel Murray wrote:
Does anyone know of a macro that will modify a tracked changes document in MS Word so that it adds curly brackets on either side of a deletion and square brackets on either side of an insertion?


This one works, but only on short documents, and it sometimes forgets to process the last deletion/insertion in the file:

Sub tracks2brackets()
' Based on code from: http://www.wordbanter.com/showthread.php?t=68482
' and http://wordribbon.tips.net/T012055_Automatically_Inserting_Brackets.html
' (this is a combination of two macros)

ActiveDocument.TrackRevisions = False

Number = ActiveDocument.Revisions.Count
For x = 1 To Number
Set myRev = ActiveDocument.Revisions(x).Range
This = ActiveDocument.Revisions(x).Type
If This = 2 Then
myRev.Select
Selection.InsertAfter "›"
Selection.InsertBefore "‹"
End If
If This = 1 Then
myRev.Select
Selection.InsertAfter "»"
Selection.InsertBefore "«"
End If
Next x

Dim chgAdd As Word.Revision

ActiveDocument.TrackRevisions = False

For Each chgAdd In ActiveDocument.Revisions
If chgAdd.Type = wdRevisionDelete Then
chgAdd.Reject
ElseIf chgAdd.Type = wdRevisionInsert Then
chgAdd.Accept
End If
Next chgAdd

End Sub


 
CafeTran Training (X)
CafeTran Training (X)
Netherlands
Local time: 20:10
XML Oct 20, 2016

How about going for the xml inside the docx zip package?

 
Rolf Keller
Rolf Keller
Germany
Local time: 20:10
English to German
Optimize the macro Oct 21, 2016

Samuel Murray wrote:

This one works, but only on short documents


Maybe some code parts run to slow and produce racing conditions.

(1) Suppress unnecessary screen updates by encapsulating the code:

Sub tracks2brackets()
Application.ScreenUpdating = False
... your existing Sub body goes here ...
Application.ScreenUpdating = True
end Sub

(2) Make the code faster by using only one insert instead of two:

Replace
Selection.InsertAfter "›"
Selection.InsertBefore "‹"
by
Selection = "›" + Selection + "‹"


 
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 20:10
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
@Rolf Oct 21, 2016

Rolf Keller wrote:
(2) Make the code faster by using only one insert instead of two:
Replace
Selection.InsertAfter "›"
Selection.InsertBefore "‹"
by
Selection = "‹" + Selection + "›"


Thanks, but... unfortunately, if I do this, then the macro only works on deletions, and it ignores insertions.

(1) Suppress unnecessary screen updates by encapsulating the code:

Sub tracks2brackets()
Application.ScreenUpdating = False
... your existing Sub body goes here ...
Application.ScreenUpdating = True
end Sub


This seems to have an effect but since the screen doesn't update, it becomes difficult to tell whether Word is still working.


 
Rolf Keller
Rolf Keller
Germany
Local time: 20:10
English to German
Macro enhancements, continued Oct 21, 2016

Samuel Murray wrote:

if I do this, then the macro only works on deletions, and it ignores insertions.


I swapped the angle brackets, sorry.

since the screen doesn't update, it becomes difficult to tell whether Word is still working.


The standard solution for this is a messagebox. Just insert
MsgBox "Done!"
at the end.


 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

MS Word macro to manipulate tracked text






Trados Studio 2022 Freelance
The leading translation software used by over 270,000 translators.

Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop and cloud solution, empowering you to work in the most efficient and cost-effective way.

More info »
Wordfast Pro
Translation Memory Software for Any Platform

Exclusive discount for ProZ.com users! Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value

Buy now! »