How to use Doc.createReplaceDescriptor in a textBox in libreoffice macros?

I read the documentation of OpenOffice.org BASIC. Tried using the Doc.createReplaceDescriptor to replace a piece of text in a textbox in a libreoffice writer macro ( replace “two” by “2” ) but I realized it does not work with the text box. When I inserted “two” out of the textbox, it worked fine!!! Please can someone tell me if there is a way of making it work with text box?

The file containing the textbox was created out of the macro ( it is in a file I had created and saved before using libreoffice writer then opened to change “two” into “2”). Here is the piece of code in charge of that

Sub insertDataIntoTemplate(Optional pDoc As Object)
REM Reworked to also run in very old versions.

If IsMissing(pDoc) Then
 theDoc = ThisComponent
Else
  theDoc = pDoc
End If

docUrl = theDoc.URL

If NOT FileExists(docUrl) Then
  MsgBox("The document must be saved to an URL for this routine to work.")
  Exit Sub
End If

If NOT theDoc.supportsService("com.sun.star.text.TextDocument") Then
  MsgBox("This routine can only export Writer documents.")
  Exit Sub
End If

Dim Replace As Object
Dim oTextField As Object
Replace = pDoc.createReplaceDescriptor
Replace.SearchString = "two"
Replace.ReplaceString = "2"

pDoc.replaceAll(Replace)

End Sub

XSearchable or XReplaceable for text documents cannot include text contained in shapes.
If you urgently need to F&R into shapes, you need to write more delicate user code.

A raw tinkered example (which cost me some time nonetheless) you find in the attachment.

findReplaceAlsoIntoShapeText0.odt

===Editing 2020-12-06 about 17:30UTC ===
The announced attachment:
findReplaceAlsoIntoShapeText2.odt

Thanks for the promptness and the response it works now, but any change made in the font (bold, font family or font size) is reset to default after the F&R. And this is only inside the shape.

…but any change made in the font (bold, font family or font size) is reset to default after the F&R. And this is only inside the shape.

That’s what I hinted to by the two text paragraphs at the end of my very short exmple document.

As far as I can see, there is no sufficiently efficient remedy.
The very first example in the mentioned document (Aha: ATwood) with its different attributing demonstrates that also ordinary F&R ignores attribute changes inside of a single finding and its replacement.
Text in shapes needs to be handled by explicitly processing the string. Writiung back the processed string will unavoidably apply one common formatting.
If you want to get the same behaviour as F&R shows for the full-featured text of the documents (outside shapes), you need to do a lot more of ticklish analysis, saving attribute values, and applying them later again explicitly.
Have a lot of fun!

I also considered to convert shape-texts to ordinary texts of TextTable cells in a helper document, which would do the limited preservation of attributes, and then to paste back the results.
I couldn’t find a way to select the shape-text which would be a condition for passing it to a XTransferaböle object. Every attempt leaded to a state where the whole shape was selected.
I suppose this goes back to fundamental design decisions concerning the API around the year 2000. Texts in shapes (and also in spreadsheet cells) are “identified” in a sense with the shape (or cell) itself. The issue under discussion here isn’t the only one related to this fact (IMO).

Alright guess I will just keep the default font. Thanks so much for your help.

Unfortunately my tinkered code was very raw, and unfortunately it obviously wasn’t the “final” version which was lost unfortunately. I just am recreating it (so far), and will attach the result to my answer soon.