Ozgrid Excel Help & Best Practices Forums

Excel Training / Excel Dashboards Reports

Results 1 to 2 of 2

Thread: Export sheet as UTF-8 CSV file (using Excel-VBA)

  1. #1
    Join Date
    6th December 2010

    Export sheet as UTF-8 CSV file (using Excel-VBA)

    I would like to export a file I have created in UTF-8 CSV using VBA. From searching message boards, I have found the following code that converts a file to UTF-8 (from this thread):
    Sub SaveAsUTF8() 
        Dim fsT, tFileToOpen, tFileToSave As String 
        tFileToOpen = InputBox("Enter the name and location of the file to convert" & vbCrLf & "With full path and filename ie. C:\MyFolder\ConvertMe.Txt") 
        tFileToSave = InputBox("Enter the name and location of the file to save" & vbCrLf & "With full path and filename ie. C:\MyFolder\SavedAsUTF8.Txt") 
        tFileToOpenPath = tFileToOpen 
        tFileToSavePath = tFileToSave 
    Set fsT = CreateObject("ADODB.Stream"): 'Create Stream object
    fsT.Type = 2: 'Specify stream type – we want To save text/string data.
    fsT.Charset = "utf-8": 'Specify charset For the source text data.
    fsT.Open: 'Open the stream
    fsT.LoadFromFile tFileToOpenPath: 'And write the file to the object stream
    fsT.SaveToFile tFileToSavePath, 2: 'Save the data to the named path
    End Sub 

    However, this code only converts a non-UTF-8 file to UTF-8. If I were to save my file in non-UTF-8 and then convert it to UTF-8, it would have already lost all the special characters it contained, thus rendering the process pointless!

    What I'm looking to do is save an open file in UTF-8 (CSV). Is there any way of doing this with VBA?

    Edit: I have now asked this question on Stack Overflow as well, due to lack of response here.
    Last edited by CaptainProg; October 2nd, 2012 at 19:06.

    Excel Video Tutorials / Excel Dashboards Reports

  2. #2
    Join Date
    16th June 2005

    Re: Export sheet as UTF-8 CSV file (using Excel-VBA)

    sorry... didnt see your question before now...this might help... http://www.ozgrid.com/forum/showthread.php?t=164547

    Check out our new reputation system. Click on the "star" under the post!

    There are 10 types of people in the world. Those that understand Binary and those that dont.

    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25...

    The BEST Lookup function of all time

    Dynamic Named Ranges are your bestest friend


Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Export Excel Sheet to txt file
    By Eat at Joe's in forum Excel General
    Replies: 2
    Last Post: September 4th, 2012, 10:22
  2. Export text file from Excel using Excel file name
    By CDB0EWM in forum Excel General
    Replies: 2
    Last Post: January 25th, 2012, 15:50
  3. Export cell content to TXT file with specific name from sheet
    By Frank Bremster in forum Excel General
    Replies: 1
    Last Post: November 15th, 2011, 21:36
  4. Replies: 5
    Last Post: July 19th, 2011, 22:20
  5. Replies: 2
    Last Post: October 20th, 2010, 04:20


Posting Permissions

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