+ Reply to Thread
Results 1 to 5 of 5

utf-8 -> windows-1252 -> utf8 conversion in VBA

  1. #1
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    utf-8 -> windows-1252 -> utf8 conversion in VBA

    Hi all,

    I have a text file with millions of lines of text that has wrongly de/recoded text like: "für" instead of "fr".
    I know this is due to mix ups between UTF-8 and Windows-1252.
    I see a C# solution here, but couldn't find a VBA solution.

    If anyone can help out, that would be much appreciated!
    Thanks,

    Jasper

  2. #2
    Registered User
    Join Date
    03-30-2014
    Location
    Pittsburgh,PA
    MS-Off Ver
    Office 2010, Home Student 2013
    Posts
    62

    Re: utf-8 -> windows-1252 -> utf8 conversion in VBA

    I found a possible vba solution at http://www.di-mgt.com.au/howto-conve...e-to-utf8.html.

    I did not test this solution.

  3. #3
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: utf-8 -> windows-1252 -> utf8 conversion in VBA

    Thanks for the suggestion, but I cannot get that to work...

  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: utf-8 -> windows-1252 -> utf8 conversion in VBA

    it might be worth posting a sample of the text and what you think it should be. Otherwise it is difficult to test anything.


    click on the * Add Reputation if this was useful or entertaining.

  5. #5
    Registered User
    Join Date
    03-30-2014
    Location
    Pittsburgh,PA
    MS-Off Ver
    Office 2010, Home Student 2013
    Posts
    62

    Re: utf-8 -> windows-1252 -> utf8 conversion in VBA

    Excel's handling of UTF-8 is a frequent annoyance for me. I don't know if it's possible to re-read and correct strings once they've been loaded into Excel. I am very interested in that solution.

    Another lead:
    Reading UTF-8 into Excel using ADODB: http://www.ozgrid.com/forum/showthread.php?t=164547

    My current work-around when I encounter this problem is to open the file in a code editor, Vim. From there it's trivial (if you know the proper incantations) to convert line endings from "dos" to "unix", set the encoding to UTF-8, and add a byte-order-mark, BOM.

    I save the file with a .txt extension and Excel's text import wizard correctly recognizes the encoding and uses Windows code page 65001. If I forget to add the BOM, I have to manually set the "File origin" on the first page of Excel's import wizard.

    I should note that I rarely work with non-latin characters: Greek, Cyrillic, Kanji, Hangul, Vietnamese, or any of the Chinese language encodings.

    • Most text editors choke on large files. 32-bit Vim can handle file sizes to 2Gb (2^31 - 1). 64-bit Vim should be able to handle into the exabyte range.
    • Good text/code editors can have atrociously steep learning curves. I'm looking at Vim and Emacs, especially. Or the software can have extremely heavy resource requirements, as with IDEs such as Eclipse.
    • UTF-8 encoding does not require a BOM. Microsoft's software chokes when the BOM is missing. Other software may choke when the BOM is included.
    • Microsoft documentation is not helpful when it implies that Unicode equals UTF-16.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 06-20-2013, 09:30 AM
  2. Utf8 encoding
    By reikia2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2012, 03:05 PM
  3. Replies: 0
    Last Post: 05-12-2012, 09:30 AM
  4. Replies: 8
    Last Post: 06-16-2011, 11:49 AM
  5. Multiple windows problem after conversion to .xlw
    By natebob in forum Excel General
    Replies: 0
    Last Post: 02-25-2010, 03:59 PM
  6. VBA Excel =?windows-1252?Q?=93Set=94_question?=
    By John Thomas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-26-2006, 03:50 PM
  7. [SOLVED] Deploying =?windows-1252?Q?=93Analysis_ToolPak=94?=
    By Will Butler in forum Excel General
    Replies: 3
    Last Post: 01-16-2005, 01:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1