I have a macro that finds words in one array and replaces them with corresponding ones in another. Essentially it is:
BritWords() = Array("fibre", "foetal")
USWords() = Array("fiber", "fetal")
Doc = ThisComponent
Replace = Doc.createReplaceDescriptor
For I = LBound(BritWords()) To UBound(BritWords())
Replace.SearchString = BritWords(I)
Replace.ReplaceString = USWords(I)
Doc.replaceAll(Replace)
Next I
It works great, but with the problem that the case of replacement word is imposed on the original word. So in the above case, if “Fibre” is at the beginning of a sentence, and thus is capitalized, it will be replaced with “fiber”, which is a usage error.
So I’m looking for a way to respect the case of the word being replaced. Would it be to capture the capitalization state and then impose it immediately after the replacement? Or is there a parameter that could be set for .doc.replaceAll(Replace) (perhaps involving Regex if no other way?) to carry the case through? Thanks.