簡體   English   中英

使用VBA以編程方式向Excel工作表中添加幾個按鈕

[英]Programmatically add several buttons to an Excel worksheet with VBA

我設法以編程方式向帶有關聯宏的工作表中添加了一個按鈕,但是當我嘗試向關聯的宏添加更多按鈕時遇到了問題,這是我使用的代碼:

'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)

因此您可以引用添加的Button ,而不是Buttons集合。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM