If the formulas are as you want, but need a refresh after the changes to them without using the editor, you can call this simple piece of code without the lines “commented away”.
If you also have Writer documents with formulas still needing the removal of the unwanted keyword, the mentioned lines need to be put in function. The cose can easily be adapted to similar tasks.
Sub dePhantomizeAndRefreshAllMathOleShapes()
REM The lines commented out by ' are only needed if the removal of "phantom"
REM keyword is not yet done. Remaining the refresh functionality.
'fa = createUnoService("com.sun.star.sheet.FunctionAccess")
doc = ThisComponent
cCtrl = doc.CurrentController
sel = doc.CurrentSelection
dp = doc.DrawPage
fr = cCtrl.Frame
dh = createUnoService("com.sun.star.frame.DispatchHelper")
For Each sh in dp
If sh.supportsService("com.sun.star.text.TextEmbeddedObject") Then
oleComponent = sh.Component
If oleComponent.supportsService("com.sun.star.formula.FormulaProperties") Then
' formula = oleComponent.Formula
' newFormula = fa.callFunction("REGEX", Array(formula, "(?i)\bPHANTOM\b", "", "g"))
' oleComponent.Formula = newFormula
cCtrl.select(sh)
refreshOleObject(sh, fr, dh)
End If
End If
Next sh
cCtrl.select(sel)
End Sub
Sub refreshOleObject(pOleShape As Object, pDispatchProvider As Object, pDispatchHelper As Object) REM Refresh rendering
Dim args(0) as new com.sun.star.beans.PropertyValue
args(0).Name = "VerbID"
args(0).Value = -1
pDispatchHelper.executeDispatch(pDispatchProvider, ".uno:ObjectMenue", "", 0, args())
pDispatchHelper.executeDispatch(pDispatchProvider, ".uno:TerminateInplaceActivation", "", 0, Array())
End Sub