Ask Your Question

Counting Track Changes

asked 2019-10-17 16:05:37 +0100

wolffe gravatar image
  • LibreOffice Version: (x64)
  • Running on Windows 10

I'm searching for a way to count the number of changes made by an editor on a document. There is a macro that does this for Word, but it hasn't been updated since 2015 and I'm not savvy enough with macros to be able to write one for LibreOffice.

The version for Word I found is here:

I've googled for a LibreOffice version and found nothing but that doesn't mean it isn't out there.

I tried copying the lines from the "Manage" window so I could paste them into a Calc document, but it won't let me do that. I'm talking hundreds of changes so counting manually really isn't an option. I just want a simple number of how many changes were tracked on a document. Does anyone know of a way I can do this?

Thank you!

edit retag flag offensive close merge delete


Service for this exists:

More late I try how...

mauricio gravatar imagemauricio ( 2019-10-17 23:19:35 +0100 )edit

I don't know what a service is or how to implement it.

wolffe gravatar imagewolffe ( 2019-10-17 23:58:21 +0100 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-10-18 00:58:42 +0100

mauricio gravatar image

updated 2019-10-18 04:54:38 +0100

With this code, we get.

doc = XSCRIPTCONTEXT.getDocument()

i = 0
d = 0

for paragraph in doc.Text:
    is_change = False
    for part in paragraph:
        if is_change:
            is_change = False
            if part.String:
                if insert:
                    i += 1
                elif delete:
                    d += 1
            insert = False
            delete = False
        if part.TextPortionType == 'Redline':
            is_change = True
            if part.RedlineType == 'Insert':
                insert = True
            elif part.RedlineType == 'Delete':
                delete = True

msg = 'Insertions: {}\nDeletions: {}'.format(i, d)

image description

With Basic is little bit complicate, but possible.

edit flag offensive delete link more


I'm sorry, I don't know how to get this to work. Can you walk me through the steps of using this please? I tried adding it as a macro, but honestly I don't know what I'm doing. Thank you so much, this is exactly what I want, I just don't know how to make it work. If you can break down exactly where to put it, I would be very grateful.

wolffe gravatar imagewolffe ( 2019-10-18 01:19:15 +0100 )edit

ok, try with Basic version, (Basic is boring)

Sub Main()
    doc = ThisComponent

    i = 0
    d = 0
    e1 = doc.Text.createEnumeration()
    Do While e1.hasMoreElements
        paragraph = e1.nextElement()
        e2 = paragraph.createEnumeration()
        Do While e2.hasMoreElements()
            part = e2.nextElement()
            If part.TextPortionType = "Redline" Then
                lineType = part.RedlineType
                If e2.hasMoreElements() Then
                    part = e2.nextElement()
                End If
                If lineType = "Insert" Then
                    i = i + 1
                ElseIf lineType = "Delete" Then
                    d = d + 1
                End If      
                If e2.hasMoreElements() Then
                    part = e2.nextElement()
                End If                  
            End If

    message = "Insertions: " & i & Chr(13) & "Deletions: " & d
    MsgBox message

End Sub
mauricio gravatar imagemauricio ( 2019-10-18 04:56:03 +0100 )edit

Thank you so SO much! That works perfectly, and is just what I wanted. <3

wolffe gravatar imagewolffe ( 2019-11-01 16:38:11 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-10-17 16:05:37 +0100

Seen: 31 times

Last updated: Oct 18