Importing utf-8 coded csv to excel using VBa

Anaya Zeeshan

New Member
Joined
Nov 4, 2021
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am beyond frustrated as I can not figure out a way import utf 8 file to excel using vba. I tried macro recorder and the code is very complex which is beyond my understanding as I am a beginner. I want to use file picker to open the csv. Any help would be greatly appreciated.
Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You should not have to do anything special to open a .csv file encoded as UTF-8. Excel will detect the Unicode BOM and open an display it like any other .csv file. I just opened a UTF-8 csv file to be sure and it worked fine.

VBA Code:
Workbooks.Open Filename:="C:\Users\MyUserID\Documents\TestUTF-8.csv"

Unless by "import" you means something else besides opening the file. If so, you will need to explain that more fully.
 
Upvote 0
Does the TEXT TO COLUMNS do what you want ? (DATA tab)
 
Upvote 0
When I import the file, the characters in foreign language does not appear to be correct as you can see in the first image. second image is how they should be. special characters only appear to be correct when I manually import the data using text import option.
 

Attachments

  • utf8-1.png
    utf8-1.png
    16.7 KB · Views: 194
  • utf8-correct.png
    utf8-correct.png
    13.6 KB · Views: 195
Upvote 0
Is the desired language display also your language ? What is it ?
 
Upvote 0
When I import the file, the characters in foreign language does not appear to be correct as you can see in the first image. second image is how they should be. special characters only appear to be correct when I manually import the data using text import option.
Then the problem is not that you are importing UTF-8 which by itself is not language specific. It is is that you need the correct ANSI code page (ACP) to translate the character encoding. Can you run this bit of code and report back the code page number of your PC?

VBA Code:
Sub GetACP()
    MsgBox "ACP (ANSI Code Page) setting on this PC is " & CreateObject("WScript.Shell").RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ACP")
End Sub

Also, when you use the text import wizard, which "File Origin" are you setting to make the Hungarian special characters display correctly?


1636234466492.png
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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