It seems I have two lines of problematic codes. Without them, the codes can run well, with them included, I will get a Run-time error '1004' Application-defined or object-defined error.
What I basically want to do is to send a command with conditions from workbook C to copy a range of cells from a workbook A to workbook B, my codes as below:
And please see the two problematic lines I marked. It looked perfectly fine to me but somehow VBA won't execute it. Can anyone explain to me why is this so?
I seem to bump into similar problems as long as I am messing with lots of workbooks, so I guess this is a general problem I have when dealing with multiple workbooks and is not limited to just copying cells...
Sub TrySaveAs()
Dim wkb0 As Workbook
Set wkb0 = ThisWorkbook
Dim wkb1 As Workbook
Dim wkb2 As Workbook
Dim i As Integer
i = 2
Do Until IsEmpty(wkb0.Worksheets("Sheet2").Cells(i, 1))
Dim full_path As String
full_path = C:\something\something.xlsx
Set wkb1 = Workbooks.Open(Filename:=somename)
wkb1.SaveAs Filename:=full_path
Set wkb2 = Workbooks.Open(Filename:=someothername)
Dim last_row As Integer
last_row = wkb2.Worksheets("RAW").Range("A1").End(xlDown).Row
wkb2.Worksheets("RAW").Range(Cells(1, 1), Cells(last_row, 5)).Copy <--------problematic
wkb1.Worksheets("Sheet1").Range(Cells(1, 1), Cells(last_row, 5)).Paste <--------problematic
wkb2.Close SaveChanges:=False
wkb1.Close SaveChanges:=True
i = i + 1
Loop
End Sub