使用VBA以编程方式向Excel工作表添加多个按钮
我设法以编程方式将按钮添加到具有关联宏的工作表中,但当我尝试添加更多具有关联宏的按钮时遇到问题,我使用的代码如下:使用VBA以编程方式向Excel工作表添加多个按钮,vba,excel,Vba,Excel,我设法以编程方式将按钮添加到具有关联宏的工作表中,但当我尝试添加更多具有关联宏的按钮时遇到问题,我使用的代码如下: 'Adding the first button With newWorkBook.Worksheets(1).Buttons .Add 350, 15, 173.25, 41.25 .Caption = "Exporter" .OnAction = "'" & ThisWorkbook.FullName & "'!export_Click
'Adding the first button
With newWorkBook.Worksheets(1).Buttons
.Add 350, 15, 173.25, 41.25
.Caption = "Exporter"
.OnAction = "'" & ThisWorkbook.FullName & "'!export_Click_FCM"
End With
'Adding the second button
With newWorkBook.Worksheets(1).Buttons
.Add 350, 66.25, 173.25, 41.25
.Caption = "Ouvrir le fichier Export"
.OnAction = "'" & ThisWorkbook.FullName & "'!open_export_FCM"
End With
使用此代码时,第一个按钮显示第二个按钮的标题及其关联的宏,第二个按钮显示默认标题“button2”且没有关联的宏,如何解决此问题?每个块的前两行应为一行:
With newWorkBook.Worksheets(1).Buttons.Add(350, 15, 173.25, 41.25)
因此,您将获得对添加的按钮
的引用,而不是对按钮
集合的引用