这是一个临时答案。当OP看到代码时它将被删除
将按钮复制了大约一百次,没有错误。确保您trgtWbk
已正确关闭并且参考是免费的。我看不到整个代码以及您如何操作工作簿对象,因此很难说出您收到错误的原因。
尝试重新安排您的代码以最适合以下架构
Sub Main()
Dim wb1 As Workbook, wb2 As Workbook
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("C:\Users\...\Desktop\Book2.xlsm")
CopyActiveX "cmd1", wb1, wb2
CopyActiveX "cmd2", wb1, wb2
wb2.Save
wb2.Saved = True
wb2.Close
Set wb2 = Nothing
End Sub
Sub CopyActiveX(cName As String, ByRef srcWbk As Workbook, ByRef trgtWbk As Workbook)
Dim x As OLEObject
Dim y As OLEObject
Dim xName As String
Set x = srcWbk.Sheets("C").OLEObjects(cName)
Set y = x.Duplicate
xName = x.Name
y.Cut
trgtWbk.Sheets("C").Activate
trgtWbk.Sheets("C").Range("O1").Select
With trgtWbk.Sheets("C")
.Paste
.OLEObjects(.OLEObjects.Count).Name = xName
.Activate
End With
End Sub