Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA以编程方式向Excel工作表添加多个按钮_Vba_Excel - Fatal编程技术网

使用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)
因此,您将获得对添加的
按钮
的引用,而不是对
按钮
集合的引用