我使用下面的代码从工作簿中复制工作表并将其另存为新工作簿。其中一张床单上有一个按钮。
如何点击代码来编程按钮,以便在单击时运行下面的代码?
Private Sub PayInfo()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Run "'Workbook1.xlsm'!MyMacro"
End Sub
Sheets(Array("Data", "Repair Recap", "Settings")).Select
Sheets(Array("Data", "Repair Recap", "Settings")).Copy
ActiveSheet.Shapes("CommandButton1").Delete
ActiveSheet.Buttons.Add(513, 9.75, 84.75, 28).Select
Selection.Name = "New Button"
Selection.OnAction = "'Customer Mailmerge.xlsm'!Button5_Click"
ActiveSheet.Shapes("New Button").Select
Selection.Characters.Text = "Payment Info"
UserName = Environ("username")
ActiveWorkbook.saveas FileName:="C:\Users\" & UserName & "\Dropbox\Ample Supply Information\Tool Repair Information\Repair Estimates-Ample\" & "RP-" & ActiveSheet.Range("C7") & "- " & ActiveSheet.Range("C6") & "- " & Format$(Date, "mm-dd-yy"), FileFormat:=52