libreoffice-basic

saving a macro that formats cells as text to an extension


I have this calc macro that is working as expected. It formats the cells as "text" so that I can type February 2024 without any problem.

Is it possible to save this macro as an extension?


sub DisableAutoFormat
dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "NumberFormatValue"
args1(0).Value = 100

dispatcher.executeDispatch(document, ".uno:NumberFormatValue", "", 0, args1())

end sub

Solution

  • Use LibreOffice to save the code as .xba format.

    Also your extension will need a META-INF folder and some other XML configuration files. So, find an extension similar to what you want by searching https://extensions.libreoffice.org/. Off the top of my head, I think AltSearch uses Basic.

    Unzip the .oxt file and insert your code from the .xba file. Update any XML settings to match the changes you made. Then zip it up again. Be sure to zip at the correct directory depth or it won't work.