ゲームが作れるようになるまでがんばる日記

ゲーム制作のことを中心にゲームに関することを書いています

OpenOfficeのCalcでボタンのセル位置を取得するマクロ

OpenOfficeのCalcでシートに配置したボタンのセル位置をマクロで取得する方法。

Doc=ThisComponent
Sheet = Doc.CurrentController.ActiveSheet
DrawPage = Sheet.DrawPage
For I = 0 To DrawPage.Count - 1
  Shape = DrawPage.GetbyIndex(I)
  If Shape.getName() = "button1" Then
    row = Shape.getAnchor.getCellAddress().Row
    column = Shape.getAnchor.getCellAddress().Column
    text = "row=" + row + ",column=" + column
    MsgBox(text)
  End If
Next I

このマクロでは、配置したボタンにbutton1と名前をつけておいて、取得している。
一応、これで動作しているが、いまいち、DrawPageやShape,Formといった部分がよくわからず、もっといい方法があるかもしれない。