Adjust base font size for all formulas of ODT document

From Apache OpenOffice Wiki
Jump to: navigation, search

The task can be easily done by this macros:

REM  *****  BASIC  *****
Sub Formulator
Dim Doc As Object
Dim objects As Object
Dim obj As Object
Dim embedded As Object
Dim formula As String
Dim newFontSize As Integer
newFontSize = InputBox("New formula font size:", "BaseFontHeight", 14)
' Create document object
doc = ThisComponent
rem doc = StarDesktop.CurrentComponent
' get objects
objects = Doc.getEmbeddedObjects()
' now iterate objects
MsgBox("There are " + objects.count + " objects found.")
For i = 0 to objects.count - 1
	rem embedded = objects(i).getEmbeddedObject() 'this line produces 'Object variable not set' when i becomes 20
	embedded = objects(i).embeddedObject 'but this code works!
	rem MsgBox("i=" + i + " name=" + objects(i).name + " " + embedded.Formula)
	If embedded.supportsService("") Then
		embedded.BaseFontHeight = newFontSize
		' some tricks to force OO.o redraw formulas
		formula = embedded.Formula
		embedded.Formula = ""
		embedded.Formula = formula
	End If
Next i
End Sub

Related Links

This is a modified version of the code from here [1] (it seems that original version doesn't work in Ooo 3.1).

Other urls about this subject:

Modifications if this fails

For LibreOffice, this macro fails ("BASIC runtime error. Property or method not found: supportsService."). The error can be fixed by replacing the line

    embedded = objects(i).embeddedObject


    embedded = objects(i).embeddedObject.Component
Personal tools