ユーザー定義の関数

ユーザー定義の関数は、LibreOffice Calc で次のように操作します:

独自の関数をLibreOffice Basicで定義する

  1. Choose Tools - Macros - Edit Macros.

  2. You will now see the Basic IDE.

  3. In the Object Catalog window, double-click on the module where you want to store your macro.

  4. Enter the function code. In this example, we define a VOL(a; b; c) function that calculates the volume of a rectangular solid with side lengths a, b and c:


    Function VOL(a, b, c)
        VOL = a*b*c
    End Function

独自の関数をドキュメントにコピーする

「独自の関数をLibreOffice Basicで定義する」の手順2で マクロ ダイアログの 編集 をクリックしました。標準設定では マイマクロ → Standard → Module1マクロの記録先 が選択されています。この Standard ライブラリは、ユーザーディレクトリにあります。

ユーザーが定義した関数を Calc ドキュメントにコピーするには、次の操作を行ないます:

  1. Choose Tools - Macros - Organize Macros - Basic.

  2. マクロの記録先 フィールドから マイマクロ → Standard → Module1 を選択した上で 編集 ボタンをクリックします。

  3. Basic-IDE でユーザーが定義した関数のソースを選択して、クリップボードにコピーします。

  4. Basic-IDE を閉じます。

  5. Choose Tools - Macros - Organize Macros - Basic .

  6. マクロの記録先 フィールドから (Calc ドキュメント名) → Standard → Module1 を選択して 編集 ボタンをクリックします。

  7. ドキュメントの Basic-IDE にクリップボードの内容を貼り付けます。

独自の関数を LibreOffice Calc で適用する

Once you have defined the function VOL(a; b; c) in the Basic-IDE, you can apply it the same way as the built-in functions of LibreOffice Calc.

  1. Open a Calc document and enter numbers for the function parameters a, b and c in cells A1, B1, and C1.

  2. カーソルを別のセルに置き、次のように入力します:

    =VOL(A1;B1;C1)

  3. 関数が適用され、結果が選択したセルに表示されます。

ご支援をお願いします!