我一直在努力学习改进此代码的方法并从该站点和其他站点中获取示例-但是我似乎无法克服运行时错误 1004“工作表类的粘贴方法失败”。我有另外两个类似的宏和一个按钮,它将运行所有 3 个。它以相同的语法运行前两个,围绕粘贴到“MyQueue”文件中很好,但第三个它不会粘贴并引发此错误。任何人都可以帮忙吗?
Sub CSQAgentSummaryEdit()
Dim MyPath As String
MyPath = " path "
MyFile = " file "
QueuePath = "path "
MyQueue = " file "
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = Workbooks.Open(QueuePath)
Set wb2 = Workbooks.Open(MyPath)
Columns("A:V").Delete Shift:=xlUp
Columns("B").Delete Shift:=xlUp
Columns("C:R").Delete Shift:=xlUp
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Range("A1").Select
Selection.consolidate Sources:= _
"'file data " _
, Function:=xlSum, LeftColumn:=True
Range("A1").CurrentRegion.Delete Shift:=xlUp
Rows("1:1").Delete
Range("A1").CurrentRegion.Select
With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Copy
Workbooks.Open (QueuePath)
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(20, 0).Range("A1").Select
ActiveSheet.Paste , False
Workbooks(MyQueue).Save
Workbooks(MyFile).Close False
End Sub