Excel vba Open a .csv file with workbooks.opentext method not working

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

I have a csv file with approx 800000 data with semicolumn delimineted, and I am using below method to open this file with delimineted, It opens the csv file but not in seperate column.

Code:
Sub opencsv()


    Workbooks.OpenText Filename:=Range("B1"), DataType:=xlDelimited, Semicolon:=True


End Sub

After opening the file I can use texttocolumn method, but if we have the method that we can open the file with delimited, and why it is not working.

Thanks
Kashif
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi rpaulson,

Thanks for reply, it is .csv file and I don't know why it is not working here, please find below some sample data in the .csv file.

Sample Data:

PERIOD_START_TIME;PLMN name;RNC name;WBTS name;WBTS ID;WCEL name;WCEL ID;AVG_NON_HSDPA_PWR (M1000C138);AVE_HSPA_DL_POWER (M1000C238)
08.07.2017 00:00:00;PLMN;MSARNC2;P_BASE_TITANIUM;1232;P_BASE_TITANIUM_1;52041;18.54;26.86
08.07.2017 00:00:00;PLMN;MSARNC2;P_BASE_TITANIUM;59987;P_BASE_TITANIUM_3;52043;18.49;27.48

Thanks
Kashif

<colgroup><col width="1037" style="width:778pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
This is a bug (feature?) in Excel, if you open a "*.csv" file using .OPENTEXT then the other parameters are ignored, so Excel overrides your settings and opens the file as a standard Excel CSV. You can prove this by renaming your file to "*.txt" then your code will work.

This is also why when you attempt to open an actual comma delimited file using WORKBOOKS.OPENTEXT the FieldInfo param does nothing.

I suspect it worked for rpaulson because he didn't have a file named "*.csv".
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,540
Members
449,038
Latest member
Guest1337

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