2016-08-30 4 views
2

행을 클릭 한 버튼을 어떻게 얻을 수 있습니까?

안녕하세요 내가 여기에 일부 도움이 필요한 사람)Excel VBA - Button 인터페이스 객체의 해당 범위 가져 오기

내가 Excel에서 버튼을 만들려고 노력하고 VBA에 안돼서하지만 난 클릭 버튼의 행을 파악하는 방법에 대한 난처한 상황에 빠진입니다.

: 사진에서처럼 나는 버튼 "Sélectionner 유엔의 포스 테"를 클릭 할 때 그는 나에게 자신의 위치 여기

버튼을 만들기 위해 내 코드입니다 (이 행에 내가 클릭 버튼)을 말할 것이라고합니다 내가 이름 AssocierSessoinCandidature있는 응용 프로그램 창을

Sub PosteBtAction() 
    AssocierSessoinCandidature.Show 
End Sub 

:

Sub AjouterBoutonPoste(positionX As Integer, positionY As Integer, nom As String) 
    Set t = ActiveSheet.Range(Cells(positionX, positionY), Cells(positionX, positionY)) 
    Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height) 
    With btn 
    .OnAction = "PosteBtAction" 
    .Caption = "Sélectionner un poste" 
    .Name = nom & CStr(positionX) & CStr(positionY) 

    End With 
End Sub 

다음은 이벤트 버튼 내 코드입니다. 사실 저는 클릭하고이 정보를 응용 프로그램 창으로 보내는 위치를 얻고 싶습니다. 당신이 아래의 코드를 적용 할 수 있습니다, 나는 매우 비슷한 사용한

답변

3

통화 버튼이 범위를 얻을 수

Sub foo() 

Dim obj As Object 
Dim row_no As Integer 

Set obj = ActiveSheet.Buttons(Application.Caller) 
With obj.TopLeftCell 
    row_no = .Row 
End With 
MsgBox "The Button is in the row number " & row_no 

End Sub 
0

: 여기

내 예를 엑셀 시트입니다 버튼을 클릭하면

Sub Button24_Click() 
Dim strShape As String 
strShape = Shapes("button24").TopLeftCell.Address 
CallAnotherFunction strShape 
End Sub 

을,이 코드의 범위를 취할 것 button24 문자열로 (내가 왜 범위를 사용하지 않았는지 모르겠다면 원하는 수 있습니다) 및 함수에 전달하십시오. CallAnotherFunction

요약하면이 필요한 것입니다 :

Shapes("button24").TopLeftCell.Address 

또는

Shapes("button24").TopLeftCell.Row 
0

당신은 TopLeftCellButton 개체의 속성에 액세스 할 수 있으며 BottomRightCell을 클릭하면 아래의 하위 바운드 것을 해결 제어 :

Option Explicit 

Sub Test() 

    Dim ws As Worksheet 
    Dim btn As Object 
    Dim strAddressTopLeft As String 
    Dim strAddressBottomRight As String 
    Dim strButtonName As String 

    Set ws = ActiveSheet 

    For Each btn In ws.Buttons 
     strAddressTopLeft = btn.TopLeftCell.Address 
     strAddressBottomRight = btn.BottomRightCell.Address 
     strButtonName = btn.Name 
     Debug.Print "Range of button (" & strButtonName & "): " & _ 
      strAddressTopLeft & ":" & _ 
      strAddressBottomRight 
    Next btn 

End Sub 
관련 문제