我想关闭当前工作簿(Template.xlsm)并打开新工作簿(UI.xlsm)并以编程方式单击Button(位于UI.xlsm工作簿中)。以下是我试过的代码。
'In the Template.xlsm Workbook
Private Sub CommandButton21_Click()
Dim UIwb as Workbook
Dim UIst as Worksheet
Set UIwb = Workbooks.Open("C:\Users\inkapb\AppData\Local\Temp\EPC AutoTool\Start Screen -UI\UI.xlsm")
Set UIst = UIwb.Worksheets("Sheet2")
End Sub
'In the UI.xlsm Workbook
Private Sub Workbook_Open()
'************** To Close the Template file if it is opened
Dim Wb As Workbook
For Each Wb In Application.Workbooks
If Wb.name Like "*Template*" Then
Wb.Close 'The Control is not passing to the next line where I have written the code to click on a button.
End If
Next
ThisWorkbook.ActiveSheet.CommandButton21.value = True ' To click a Button in UI.xlsm Workbook
End Sub
有人可以帮我解决这个问题吗