I've been working on a piece of work that aims to open and copy information from one worksheet and copies it into another. Here is the script
Sub Data_API()
Dim xlApp, xlBook
Dim xlBook2 As Workbook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Users\Pear\Book2.xlsm")
Set xlBook2 = Workbooks("Extract.xlsb")
xlApp.Visible = True
xlApp.Run "ImportFile"
xlBook.Worksheets("Sheet1").Range("A2:K500").Copy
xlBook2.Activate
ActiveSheet.Paste Destination:=Worksheets("Data").Range("A2")
xlBook.Application.CutCopyMode = False
xlBook.Close False
Application.DisplayAlerts = False
End Sub
I receive an error message as follow:
Run-time error 1004: Paste Method of worksheet class failed.
When I select debug it directs me to this line of code
ActiveSheet.Paste Destination:=Worksheets("Data").Range("A2")
Any thoughts/feedback/suggested changes would be much appreciated.