Hi
I am attempting to open a csv file and then copy data from it to my main workbook. I can open the file fine but when I get to the bit of code that requests to copy the data, I get Run-time error '1004'; Application-defined or object-defined error and I cannot work out why. As far as Excel appears to be concerned, the csv file is the active workbook.
Any advice or suggestions please?
Thanks
I am attempting to open a csv file and then copy data from it to my main workbook. I can open the file fine but when I get to the bit of code that requests to copy the data, I get Run-time error '1004'; Application-defined or object-defined error and I cannot work out why. As far as Excel appears to be concerned, the csv file is the active workbook.
Code:
Sub select_report()
Dim MyFile As String
ChDir "C:\Users\******\Downloads"
MyFile = Application.GetOpenFilename("Files (*.csv),*.csv", , "Select Report File")
Workbooks.Open (MyFile)
ActiveSheet.Name = "report"
' check the active workbook
MsgBox ActiveWorkbook.Name, vbInformation, "Workbook Name"
With Sheets("report")
.Range("A2:U" & Lastrow).Copy
End With
ActiveWorkbook.Close
With Sheets("SFData")
.Range("A2").Paste
End With
End Sub
Any advice or suggestions please?
Thanks