Excel VBA - 获取Button接口对象的相应范围 [英] Excel VBA - Get corresponding Range for Button interface object

查看:231
本文介绍了Excel VBA - 获取Button接口对象的相应范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,我需要一些帮助在这里;)



我是VBA中的新手,我试图在Excel中创建一个按钮,但是我如何弄清楚点击按钮的一行。像照片中的那样,当我点击Sélectionnerun poste按钮时,他会告诉我他的位置(我点击了哪一行的按钮)



这里是我的代码来创建按钮:

  Sub AjouterBoutonPoste(positionX As Integer,positionY As Integer,nom As String)
设置t = ActiveSheet.Range(Cells(positionX,positionY),Cells(positionX,positionY))
设置btn = ActiveSheet.Buttons.Add(t.Left,t.Top,t.Width,t.Height )
与btn
.OnAction =PosteBtAction
.Caption =Sélectionnerun poste
.Name = nom& CStr(positionX)& CStr(positionY)

结束
结束子

这里是我的事件按钮的代码:

  Sub PosteBtAction()
AssocierSessoinCandidature.Show
End Sub $我有一个应用程序窗口,其名称是 AssocierSessoinCandidature 。实际上,我想获得我点击的位置并将其发送到应用程序窗口。



这是我的示例Excel工作表:

解决方案

调用以下Sub点击该按钮

  Sub foo()

Dim obj As Object
Dim row_no As Integer

设置obj = ActiveSheet.Buttons(Application.Caller)
带obj.TopLeftCell
row_no = .Row
结束
MsgBox按钮在行号& row_no

End Sub


How can I get the row the clicked button?

Hello everyone i need some help over here ;)

I'm a newbie in VBA I am trying to make a button in Excel but I am stumped on how to figure out the row of the clicked button. Like in the photo I want that when I click the button "Sélectionner un poste" then he will tell me his position (The button which i clicked in which row)

Here is my code to create the button:

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

Here is my code for the event button:

Sub PosteBtAction()
   AssocierSessoinCandidature.Show
End Sub

I have a application window which name is AssocierSessoinCandidature. Actually I want to get the position which i clicked and send this information to the application window.

Here is my example Excel sheet:

解决方案

Call the below Sub when the button is clicked

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

这篇关于Excel VBA - 获取Button接口对象的相应范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆