2014-12-30 8 views
0

사용자 지정 스프레드 시트 (Open/Libre/Star Office)의 일부 셀에 [표준] 매크로 [s]를 추가하고 싶습니다.링크 매크로의 셀 및 참조 셀에 Office 단추 열기/

해당 매크로 [s]에 드롭 된 양식 푸시 버튼을 사용하여 매크로를 활성화해야합니다.

는 내가 "관련 세포"의 접근에 몇 가지 문제가 모두 상대가 발생합니다

  1. 나는 그것이 A1로 이동 푸시 버튼이 아니라 현재 선택하는 셀에서 셀 앵커하려고합니다.
  2. 버튼에 Basic 조각을 연결할 수는 있지만 '관련 셀'(즉, 버튼이 포함 된 셀)을 검색 할 방법이 없습니다.

내가 뭘 하려는지 (첫 번째 작업 예제로서) 셀의 숫자 값을 증가시키기위한 단추를 추가하는 것입니다 (직접 편집을 비활성화 할 수도 있습니다.이 값을 각 단추마다 하나씩 올리려합니다.) 언론과 그렇지 않으면 세포를 변경하는 방법).

그런 것이 가능합니까?

모든 예제 (또는 문서에 대한 포인터) 매우입니다.

참고 : This question은 VBA (엑셀)에서 문제를 해결하는 방법에 대한 몇 가지 힌트를 제공합니다,하지만 난에 대해 아무것도 찾을 수 없습니다 [L를 | O | S] 사무실

답변

0

당신은에서 버튼을 포함하는 셀을 찾을 수 있습니다 다음과 같이 처리기 :

Sub ButtonHandler(oEvent) 

    Dim sControlName$ 
    Dim oSheet 
    Dim nCount As Long 
    Dim i As Long 
    Dim oPage 
    Dim oShape 
    Dim oAnchor 

    sControlName = oEvent.source.model.Name 
    oSheet = thiscomponent.currentcontroller.activesheet 
    nCount = oSheet.drawpage.count 
    oPage = oSheet.drawpage 

    For i = 0 To nCount - 1 
    oShape = oPage.getbyindex(i) 
    'oControlShape = oPage.getbyindex(i).control 
    If (oShape.supportsService("com.sun.star.drawing.ControlShape")) Then 
     If oShape.control.Name = sControlName Then 
     oAnchor = oShape.anchor 
     If (oAnchor.supportsService("com.sun.star.sheet.SheetCell")) Then 
      Print "Button is anchored in cell: " + oAnchor.AbsoluteName 
      Exit For 
     End If 
     End If 
    End If 
    Next i 
End Sub 

나는 알고있다, 그것은 꽤 아닌가요? 중요한 오류 검사를 추가했습니다. 버튼을 클릭했을 때 어떤 셀이 활성화되었는지 알고 싶다면이 루틴을 호출 할 수 있습니다.

Sub RetrieveTheActiveCell() 
    Dim oOldSelection 'The original selection of cell ranges 
    Dim oRanges  'A blank range created by the document 
    Dim oActiveCell 'The current active cell 
    Dim oConv   'The cell address conversion service 
    Dim oDoc 
    oDoc = ThisComponent 

    REM store the current selection 
    oOldSelection = oDoc.CurrentSelection 

    REM Create an empty SheetCellRanges service and then select it. 
    REM This leaves ONLY the active cell selected. 
    oRanges = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges") 
    oDoc.CurrentController.Select(oRanges) 

    REM Get the active cell! 
    oActiveCell = oDoc.CurrentSelection 

    oConv = oDoc.createInstance("com.sun.star.table.CellAddressConversion") 
    oConv.Address = oActiveCell.getCellAddress 
    Print oConv.UserInterfaceRepresentation 
    print oConv.PersistentRepresentation 

    REM Restore the old selection, but lose the previously active cell 
    oDoc.CurrentController.Select(oOldSelection) 
End Sub