VBA importing UTF-8 CSV file from a web server

后端 未结 3 1168
花落未央
花落未央 2021-02-18 18:39

I have a UTF-8 CSV file stored on a web server. When I download the file put it on my hard drive and I then import it into an Excel sheet with this macro (from the macro recorde

3条回答
  •  佛祖请我去吃肉
    2021-02-18 19:21

    IMO, there seems to be a bug/conflict in Excel when opening UTF-8/UTF-8-BOM files using the recorded macro code, specifically when the Origin parameter is set to 65001 which is supposed be UTF-8.

    I have found two workarounds to this issue:

    1. Remove the Origin parameter from the function call and see if the file loads properly Workbooks.OpenText Filename:="C:\file.csv".

      MSDN says:

      If this argument is omitted, the method uses the current setting of the File Origin option in the Text Import Wizard.

      I would think that as soon as you link the file with Excel, it should try to read the header of the file and select the correct Country Code automatically (well, assuming the header is not missing).

    2. I have tried different Country Codes and found that in my specific scenario setting Origin:=1252 (1252 - windows-1252 - ANSI Latin 1; Western European (Windows)) loads the file in Excel just fine.

提交回复
热议问题