+ Reply to Thread
Results 1 to 5 of 5

VBA - Import data and encode as UTF8

Hybrid View

  1. #1
    Registered User
    Join Date
    05-09-2019
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    25

    VBA - Import data and encode as UTF8

    Hello Genie-i

    Im looking for help with a macro that you can either select a file and import as 65001: Unicode UTF8 or convert a sheet dropped into a tab.

    The issue i have is a source data export comes out with characters such as ‐ when they should not be

    if i use the "from text/CSV" import function and select as 65001: Unicode UTF8 then it corrects all the special characters so i am essentially looking for something to replicate this so i can just press a button and the characters in the sheet should show as intended.

    any help is appreciated

    Thank you!
    Last edited by Makroz; 07-12-2022 at 12:28 PM.

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2405-17628.20102
    Posts
    1,392

    Re: VBA - Import data and encode as UTF8

    Are you importing from a txt file or do the values already exist on the sheet?

    If it is a txt/ csv file are you able to provide a sample file?
    If things don't change they stay the same

  3. #3
    Registered User
    Join Date
    05-09-2019
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    25

    Re: VBA - Import data and encode as UTF8

    Hey, thank you!

    I have put together a sample so hopefully its attached ok. the source file is a CSV


    Column D should read as below but its not specific to these 4 columns so im looking to correct either a full import or whatever is dropped into a worksheet. i can adjust any code ranges if required though

    Lamborghini – Magnifique

    Should be

    Lamborghini Magnifique
    Last edited by Makroz; 07-12-2022 at 11:09 AM.

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2405-17628.20102
    Posts
    1,392

    Re: VBA - Import data and encode as UTF8

    Perhaps:
    Sub test()
        Dim MyFile As String
        
        MyFile = "C:\Users\jbloggs\Desktop\test\test\Test.csv"
        
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & MyFile, Destination:=Range("A1"))
            .TextFilePlatform = 65001
            .TextFileCommaDelimiter = True
            .Refresh BackgroundQuery:=True
        End With
    End Sub
    Edit: Just noticed your XL version... Let me know if it doen not work for you.

  5. #5
    Registered User
    Join Date
    05-09-2019
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    25

    Re: VBA - Import data and encode as UTF8

    Thank you my friend this is exactly what i was looking for!

    don't worry i need to update my excel version i only just noticed

    Have a great day!

+ 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. Macro to encode in last blank cell up to the last used row.
    By mark_anthony in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-24-2014, 04:36 AM
  2. Is there a native way to encode an object as a JSON string?
    By XmisterIS in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2014, 05:32 AM
  3. How to encode an xml from UCS to UTF-8
    By kalai1587 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2013, 12:09 PM
  4. how to encode output file to utf-8
    By gak in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-25-2012, 09:45 AM
  5. Encode Text Of Body Of Email Into HTML
    By WJO in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2012, 02:27 PM
  6. Replies: 8
    Last Post: 06-16-2011, 11:49 AM
  7. Text File Encode to UTF-8_Unicode specific
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2005, 06:10 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