MS Word macro to manipulate tracked text
Thread poster: Samuel Murray

Samuel Murray  Identity Verified
Netherlands
Local time: 14:35
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 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):

bzn1vfv9hjtollcwuc75.pngr0mn6rlspkaab8edyafw.png

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]


 

Samuel Murray  Identity Verified
Netherlands
Local time: 14:35
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)
Netherlands
Local time: 14:35
XML Oct 20, 2016

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

 

Rolf Keller
Germany
Local time: 14:35
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  Identity Verified
Netherlands
Local time: 14:35
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
Germany
Local time: 14:35
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

Advanced search






BaccS – Business Accounting Software
Modern desktop project management for freelance translators

BaccS makes it easy for translators to manage their projects, schedule tasks, create invoices, and view highly customizable reports. User-friendly, ProZ.com integration, community-driven development – a few reasons BaccS is trusted by translators!

More info »
SDL Trados Studio 2019 Freelance
The leading translation software used by over 250,000 translators.

SDL Trados Studio 2019 has evolved to bring translators a brand new experience. Designed with user experience at its core, Studio 2019 transforms how new users get up and running and helps experienced users make the most of the powerful features.

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search