VBA: copy and paste from a csv to xlsm

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I'm dealing with a closed csv file called "record".
It I open it manually, it seems a pure xls file (there is one only sheet with a series of data organized in rows and columns).

I need to copy the data to thisworkbook (which obviously is a .xlsm).

But something gets wrong.

Code:
Sub copy_csv

Dim wb As Workbook
Set wb = Workbooks.Open("C:\Desktop\CSV\record.csv")

ThisWorkbook.Sheets(1).Range("B1").Value = wb.Range("A1").CurrentRegion.Value

End Sub

Error 438 object doesn't support this property or method

in the following line

Code:
ThisWorkbook.Sheets(1).Range("B1").Value = wb.Range("A1").CurrentRegion.Value

The process stops with the "record" file opened with the data displayed without columns (as in a notepad).


How can I figure it out?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try
Code:
Sub copy_csv()

Dim wb As Workbook
Set wb = Workbooks.Open("C:\Desktop\CSV\record.csv")

wb.Range("A1").CurrentRegion.Copy ThisWorkbook.Sheets(1).Range("B1")

End Sub
 
Upvote 0
Try
Code:
Sub copy_csv()

Dim wb As Workbook
Set wb = Workbooks.Open("C:\Desktop\CSV\record.csv")

wb.Range("A1").CurrentRegion.Copy ThisWorkbook.Sheets(1).Range("B1")

End Sub

Same error, same situation.
 
Upvote 0
When you said
The process stops with the "record" file opened with the data displayed without columns (as in a notepad).
Do you mean that everything is in one cell, or one column?
 
Upvote 0
Scrub that, try
Code:
[COLOR=#ff0000]wb.Sheets(1).[/COLOR]Range("A1").CurrentRegion.Copy ThisWorkbook.Sheets(1).Range("B1")
 
Upvote 0
Scrub that, try
Code:
[COLOR=#ff0000]wb.Sheets(1).[/COLOR]Range("A1").CurrentRegion.Copy ThisWorkbook.Sheets(1).Range("B1")

Same error.

I mean, in the "record" file opened, all data are in range A1:A12959 instead of A1:AL12959

In A2, for instance, I can read something like this:

1094254;25/10/2018;01:00:00;Company;Brench;Sheffield;no more;ZTT;ZTT125;Seller;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0
 
Upvote 0
Could you supply a cut down version of the csv file?
If you have ; between the values rather than , then it's not a csv file.
What I don't understand is if you doubleclick the file it opens ok, but opening via VBA doesn't work
 
Upvote 0
This it what I see in folder C:\Desktop\CSV (consider italian pc, "virgola" is "comma").

https://imgur.com/a/qHW3tMF

Now, I'm going to provide an example, but I have to manipulate because of private data.
 
Last edited:
Upvote 0
No other ideas?

I think in some way it should be figured out.
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,216
Members
449,215
Latest member
texmansru47

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top