Find field, replace by plain text, keep formating

I have a book just before sending to my publisher.
I need to replace all fields by plain text but keep formating at the same time.
Have you any idea how to do it by macro or any other way than by hand?
I have hundreds of fields in my document.

Honestly, I have no idea. There even isn’t any tool how to find a field.

If you observed strict styling strategy, your fields have received a character style. This character style will not be removed during the transformation field→text. If you didn’t, you’ll have to restore the formatting.

Believe it or not, this problem was solved many years ago, the solution is described in the Wiki:Converting fields into text, but unfortunately the link to the forum does not work (it does not work for me, perhaps you can find that topic)

The code that does this trick is very simple:

Sub FieldsToText 'Writer Only!'
Dim oDoc,oFields,oEnum,ThisField
   oDoc = ThisComponent
   oFields = oDoc.getTextFields
   oEnum = oFields.createEnumeration
   While oEnum.HasMoreElements
       ThisField = oEnum.nextElement
       ThisField.Anchor.String = ThisField.Anchor.String
End Sub

(This was written 6 years ago, I haven’t tested it, but it should still work)

FTR: the archived version of the forum topic mentioned in the Wiki is here.

So, JohnV write it Sat Feb 12, 2011? More then 10 years ago… Thank you!

Believe me or not - I love when smart people are generous!
Thank you all! :slight_smile:
PS. It works almost perfectly - only table of contents and links to pictures remained intact. So no problem, I can cope…