i am struggling with a problem, I have many documents created by myself and co-editors they contain highlights of different color.
They are saved in .docx format I know it was an mistake I should have only transferred it to this format in the last step but my clients requested it llike this and I made the mistake to follow them, in my own workflow...for no reason. They contain different colored higlightings and I need to unify some of the colors to only specific ones.
I first attempted it with the find and replace but apparently it is buggy because of the .docx format or something and it doesnt work. So I thought doing it with a macro. I am really a beginner programmer with only very limited knowledge of python. But together with the macro recorder and the macro editor I played around a little to see what is happening.
I wanted to avoid the find and replace function because of the bug cause I thought the find and replace in the gui also only uses this function so my idea was:
1. Create an array containing the paragraphs. ( Somehow it was easier to just use the enumerate function but it works.)
2. Run a for-loop on the array.
3. Checking if the element is a paragraph.
4. Checking if the highlight color, I want to change is present, with an nested If statement.
5. If it is exchange it with the one specified.
6. Checking another color with If-Statement.
7. Else continue.
Thats it.
Code: Select all
Sub Special
dim oEnum
dim oPar
dim bumred
dim bumgre
oEnum = ThisComponent.Text.createEnumeration()
oPar = oEnum.nextElement()
REM print oEnum
Do While oEnum.hasMoreElements()
bumred = oPar.getPropertyValue("CharBackColor")
REM print bumred
If oPar.supportsservice("com.sun.star.text.Paragraph") Then
If bumred Is 9701130 Then
oPar.setPropertyValue("ParaBackColor", 16711680)
End If
End If
oPar = oEnum.nextElement()
REM print "nicht rot"
Loop
REM print "don"
End Sub
Thanks people