获取单元格中的CommandButton名称/ ID

我有一个单元格与CommandButtons的电子表格。 我只是想在没有button被点击的情况下获取特定单元格中的命令button的名称/ ID。 我怎么能去呢? 我一直在使用这个代码,但效率不高,因为我必须逐个键入每个buttonID。 我有大约60个button。

Sub Worksheet_Calculate() If Cells(6, 3).Value = 0 Then Me.Buttons("Button 55").Enabled = False Me.Buttons("Button 55").Font.ColorIndex = 16 Else Me.Buttons("Button 55").Enabled = True Me.Buttons("Button 55").Font.ColorIndex = 1 End If If Cells(7, 3).Value = 0 Then Me.Buttons("Button 61").Enabled = False Me.Buttons("Button 61").Font.ColorIndex = 16 Else Me.Buttons("Button 61").Enabled = True Me.Buttons("Button 61").Font.ColorIndex = 1 End If 

一种方法是循环浏览工作表上的所有button,并检查TopLeftCell与您的单元格是否匹配。 可能会陷入很多button,但我认为60将运行良好。 如果你有重叠的button,可能会遇到问题,但你可能会避免。 这看起来在所有Shapes ,它可能会缩小一些,但我不知道你正在使用哪种types的button。

 'In a worksheet module change Me. to a worksheet as needed. Function findShape(r As Range) As String Dim s As Shape findShape = "Not Found" 'if loop goes all the way around and doesn't find it. For Each s In Me.Shapes If s.TopLeftCell.Address = r.Address Then findShape = s.Name Exit For 'no need to keep going End If Next End Function