Convert Track Changes to Formatting

I’ve written a little macro for Libreoffice Writer that:

  • rejects track changes of deletions and formats the text with a strikeout and changes the font color to red
  • accepts track changes of insertions and formats the text with an underline and changes the font color to blue
  • accepts track changes of formatting i.e. italics and changes the font color to orange

It is directed at simple manuscripts that have no tables, footnotes, etc.

After the macro has been run, the document can be saved as an rtf for import to Scrivener. Track changes should still be done in Writer. This has only been tested on odt files, so I have no idea if it will work with a Word doc file that has been saved to odt.

As always, when trying something for the first time: backup and/or use copies.

Sub ConvertTrackChangesToFormatting
	dim doc as object
	dim viewCursor as object
	dim redLines as object
	dim redLine as object
	dim document as object
	dim dispatcher as object
	dim count as long
	dim args2(0) as new
	dim args3(0) as new
	dim args4(2) as new
	dim args5(0) as new
	dim args6(0) as new
	args2(0).Name = "Strikeout.Kind"
	args2(0).Value = 1

	args3(0).Name = "FontColor"
	args3(0).Value = 16711680
	args4(0).Name = "Underline.LineStyle"
	args4(0).Value = 1
	args4(1).Name = "Underline.HasColor"
	args4(1).Value = false
	args4(2).Name = "Underline.Color"
	args4(2).Value = -1
	args5(0).Name = "FontColor"
	args5(0).Value = 255
	args6(0).Name = "FontColor"
	args6(0).Value = 16744192
	doc = ThisComponent
	viewCursor = doc.CurrentController.ViewCursor
	document   = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("")
	redLines = doc.Redlines
	count = redLines.getCount() - 1
	for i = 0 to count
		redLine = redLines.getByIndex(0) 'does not work with getByIndex(i)
		viewCursor.gotoRange(redLine.RedlineStart, false)
		viewCursor.gotoRange(redLine.RedlineEnd, true)
		if redLine.RedlineType = "Delete" Then
		'Strikeout text, change font color to red, and reject track change
		  	'dim args2(0) as new
			'args2(0).Name = "Strikeout.Kind"
			'args2(0).Value = 1
			dispatcher.executeDispatch(document, ".uno:Strikeout", "", 0, args2())
			'dim args3(0) as new
			'args3(0).Name = "FontColor"
			'args3(0).Value = 16711680
			dispatcher.executeDispatch(document, ".uno:FontColor", "", 0, args3())
			dispatcher.executeDispatch(document, ".uno:RejectTrackedChange", "", 0, Array())
		elseif redLine.RedlineType = "Insert" Then
		'Underline, change font color to blue, and accept track change
			'dim args4(2) as new
			'args4(0).Name = "Underline.LineStyle"
			'args4(0).Value = 1
			'args4(1).Name = "Underline.HasColor"
			'args4(1).Value = false
			'args4(2).Name = "Underline.Color"
			'args4(2).Value = -1
			dispatcher.executeDispatch(document, ".uno:Underline", "", 0, args4())
			'dim args5(0) as new
			'args5(0).Name = "FontColor"
			'args5(0).Value = 255
			dispatcher.executeDispatch(document, ".uno:FontColor", "", 0, args5())
			dispatcher.executeDispatch(document, ".uno:AcceptTrackedChange", "", 0, Array())
		elseif redLine.RedlineType = "Format" Then
		'change font color to orange and accept track change
			'dim args6(0) as new
			'args6(0).Name = "FontColor"
			'args6(0).Value = 16744192
			dispatcher.executeDispatch(document, ".uno:FontColor", "", 0, args6())
			dispatcher.executeDispatch(document, ".uno:AcceptTrackedChange", "", 0, Array())
		end if
	next i
End Sub

This is awesome!! :smiley: I googled over 4 hours to find a solution to my problem. I write on Scrivener, but my colleagues want to do edits on Google Docs, which I then convert to Libre Office, run your macro and copy back to Scrivener to take a snapshot. I then proceed to ‘accept’ or ‘reject’ the changes.

May I ask, how do you use your macro ?

I would like to use either an Alfred workflow, or a javascript template in Copied to copy directly from Google Docs to formatted text (underline, superscript) in Scrivener. I do wish there was something easier. Unfortunately I am not a programmer. :frowning:

Cheers! And thanks for sharing this!!