2009-02-26 84 views
0

我有一個在OpenOffice中啓動宏的按鈕。在宏中,我想更改按鈕的名稱。 Excel的原始代碼是如何解決按鈕問題? (OpenOffice電子表格宏)

ActiveSheet.Shapes("PunchButton").select 
    Selection.Characters.Text = "Punch In" 

但第一行什麼都不做。我已經在OpenOffice中檢查過該工作表,並且該按鈕有正確的名稱。我如何得到它?

回答

1

有一段代碼here,它顯示瞭如何更改所有按鈕的標籤和狀態,但只有您想要的那個。

Sub clickCommandButton1 
    oPage = Thiscomponent.Sheets.getByName("Sheet1").getDrawPage 
    iCount = oPage.getCount 
    For i = 0 to iCount - 1 
     oEle = oPage.getByIndex(i) 
     oControl = oEle.getControl() 
     If oControl.DefaultControl = "com.sun.star.form.control.CommandButton" Then 
      ' Found command button - change label of other buttons ' 
      If oEle.Name <> "CommandButton1" Then 
       oControl.Label = "Inactive" 
       oControl.Enabled = False 
      End If 
     End If 
    Next 
End Sub 

我將修改這在遍歷所有的按鈕,但改變內部if語句爲「=」,而不是‘<>’(並刪除禁用如果這是沒有必要的)。

+0

太好了,謝謝你。我會檢查出來,並張貼我的代碼當它工作。 – 2009-02-26 06:16:33

0

謝謝到大同,這是我工作的代碼。不知道它是,但該板在問題它是如何工作的魯棒性。再次感謝,大同。

sub testThis 
    setButtonLabel("PunchButton", "hello") 
    setButtonLabel("ReportButton", "hello") 
end sub 

sub setButtonLabel(controlName, label) 
    oPage = ThisComponent.CurrentController.ActiveSheet.getDrawPage 
    iCount = oPage.getCount 
    For i = 0 to iCount - 1 
     oControl = oPage.getByIndex(i).getControl 
     If oControl.Name = controlName Then 
      oControl.label = label 
      exit sub 
     End If 
    Next 
end sub