更新时间:2023-12-03 14:24:28
p>我认为这足以使你有一个很好的路径:
Sub a()
Dim btn As按钮
Application.ScreenUpdating = False
ActiveSheet.Buttons.Delete
Dim t As Range
For i = 2 To 6 Step 2
Set t = ActiveSheet.Range单元格(i,3),单元格(i,3))
设置btn = ActiveSheet.Buttons.Add(t.Left,t.Top,t.Width,t.Height)
带有btn
.OnAction =btnS
.Caption =Btn& i
.Name =Btn& i
结束
下一步i
Application.ScreenUpdating = True
End Sub
Sub btnS()
MsgBox Application.Caller
End Sub
它创建按钮并将其绑定到butnS()。在btnS()子中,您应该显示对话框等。
I have a function that generates data for say 100 cell rows (and 2 columns). For each row (in the 3rd column) I need to add a button which, when clicked, brings up a custom modal dialog box giving the user 4 options/buttons to choose from.
Any idea how to do this?
/T
I think this is enough to get you on a nice path:
Sub a()
Dim btn As Button
Application.ScreenUpdating = False
ActiveSheet.Buttons.Delete
Dim t As Range
For i = 2 To 6 Step 2
Set t = ActiveSheet.Range(Cells(i, 3), Cells(i, 3))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "btnS"
.Caption = "Btn " & i
.Name = "Btn" & i
End With
Next i
Application.ScreenUpdating = True
End Sub
Sub btnS()
MsgBox Application.Caller
End Sub
It creates the buttons and binds them to butnS(). In the btnS() sub, you should show your dialog, etc.