文書更新:2019年06月18日(火) 午前10時38分43秒

Home > 備忘録 > libreoffice の macro(basic) > sheet 内のコントロールを操作( 97 )

sheet 内のコントロールを操作

コンピュータの超初心者のため、下記のコードが正しいのか分かりません。偶然にできたかもしれません。コントロールの名前は「my_ctrl_button」としています。
  1. Sub Demo1
    	Dim objSheet,objForm,objCtrl As Object
    	Dim j As Integer
    	objSheet=ThisComponent.CurrentController.Activesheet
    	objForm=objSheet.Drawpage.Forms.GetbyIndex(0)
    	objCtrl=objForm.getByName("my_ctrl_button")
    	'ここでコントロールに対する処理をおこなう( objCtrl )
    	'MsgBox objCtrl.DBG_Methods
    	'MsgBox objCtrl.DBG_Properties
    End Sub
  2. Sub Demo1
    	Dim objSheet,objForm As Object
    	Dim j As Integer
    	objSheet=ThisComponent.CurrentController.Activesheet
    	objForm=objSheet.Drawpage.Forms.GetbyIndex(0)
    	For j=0 To objForm.Count-1
    		If objForm.GetbyIndex(j).Name="my_ctrl_button" then
    			'ここでコントロールに対する処理をおこなう( objForm.GetbyIndex(j) )
    			'MsgBox objForm.GetbyIndex(j).DBG_Methods
    			'MsgBox objForm.GetbyIndex(j).DBG_Properties
    		End If
    	Next j
    End Sub
下記は例題です
  1. 日付コントロールの日付けを変更する
  2. 日付コントロールの名前は「my_ctrl_button」としています。
    2015年12月23日に変更する
    Sub Demo2
    	Dim objSheet,objForm As Object
    	Dim j As Integer
    	objSheet=ThisComponent.CurrentController.Activesheet
    	objForm=objSheet.Drawpage.Forms.GetbyIndex(0)
    	For j=0 To objForm.Count-1
    		If objForm.GetbyIndex(j).Name="my_ctrl_button" then
    			Dim hiduke As New com.sun.star.util.Date
    			hiduke.Year=2015
    			hiduke.Month=12
    			hiduke.Day=23
    			objForm.GetbyIndex(j).Date=hiduke
    		End If
    	Next j
    End Sub