0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VBA on Libre Calc - シート操作・文字列編集・ファイル出力 -

Posted at
1 / 2

ためしてガッテン!!

LibreOffice CalcでVBAが使えるという記事をいくつか見かけてテンションがあがりました。
と同時に「ここができないと」と気になったのが以下の3点です。

  • シートの操作
  • 文字列編集
  • ファイル出力

これらが扱えるとVBAの知識を活かしてCalcをCSVなどのデータ作成・生成ツールとして活用しやすいです。
Calcで実験 ⇒ Excelで実用なんてことにも応用できます。

結論

1時間程度のお試しですが、実用性はあると感じました。LibreOfficeの人たちすごい。
環境を記載したあと、試した関数等をご紹介します。

環境

Windows 10
LibreOffice 6.4

シートの操作


    ' アクティブなシートのセルに値を設定
    activesheet.cells(1,1) = "Good"

    ' シート名を指定して値を設定
    worksheets("Sheet2").cells(2,5) = "Weldone"

    ' シートの追加
    worksheets.add

    ' シート数の取得
    worksheets.count

    ' 指定のシートをアクティブに
    worksheets("Sheet1").activate

文字列編集


orgStr = "てくのぽりす"

' left
print #1, left(orgStr,3)

' mid
print #1, mid(orgStr,3,2)

' right
print #1, right(orgStr,3)

' len
print #1, len(orgStr)


spacedStr = " VBA "

' trim
print #1, trim(spacedStr)


てくの
のぽ
ぽりす
6
VBA

ファイル出力


' オープン
Open "E:\test.txt" For Output As #1

' 出力
print #1, "Marvelous"

' クローズ
close #1

※出力先には注意して下さい。"C:\test.txt" 等は通常アプリから書けないので「デバイスI/Oエラー」になります。

最後に

まだまだ確認すべきものはありますが、「試していこう」と感じられるほどに動いてくれました。

参考になればこれ幸いというところです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?