Creating module at runtime

How can I create a new module in a chosen library using libreoffice basic code?

I’ve tried: ThisComponent.getLibraryContainer().getByName(“C_calc”).getModuleContainer().insertByName(“newModule”, “”) with no effect. It throws an exception:

Type:com.sun.star.lang.IllegalArgumentException Message: types do not match at ./basic/source/basmgr/basmgr.cxx:1738.

How can I solve this problem?

Hi, try this way

Sub Main
PysLib = BasicLibraries.getByName("C_calc")
If PysLib.hasByName("newModule") = False then
  PysLib.insertByName("newModule", "")  
end if
End Sub
1 Like

It is magically solved!!! Thanks a lot…

1 Like