2

I am working through Excel for Engineers and trying to adapt it for LibreOffice Calc. I have run into a problem. I know this is easier to do without using macros but humor me. One of the exercises is to start recording a macro, type:

=RAND()

hit enter and stop recording.

When I run the macro nothing happens. I try to use any other Calc built in function and the same thing happens. Looking at the macro basic file and sure enough nothing is happening.

Can I use built in functions when recording a macro? If so how?

4

1 回答 1

2

目前,LibreOffice 宏录制器不录制添加内置函数。事实上,记录器有很多限制,通常会导致代码很差(主要使用调度程序)。

相反,根据文档编写 API 代码,例如https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Function_Handling

Sub CallSpreadsheetFunction
    funcAcc = createUnoService("com.sun.star.sheet.FunctionAccess")
    oSheet = ThisComponent.getSheets().getByIndex(0)
    oCell = oSheet.getCellRangeByName("A1")
    oCell.setValue(funcAcc.callFunction("RAND", Array()))
End Sub

开始学习 LibreOffice 宏的一个好地方是http://www.pitonyak.org/oo.php

请注意,学习 LibreOffice Basic 对了解 MS Office VBA 没有太大帮助。这两种语言和平台完全不同。

于 2018-03-22T13:08:36.543 回答