dcsimg
Results 1 to 3 of 3

Thread: VBA: Export Vietnamese data from Excel to Notepad: Unicode problem

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jun 2019
    Posts
    1

    VBA: Export Vietnamese data from Excel to Notepad: Unicode problem

    I am exporting Vietnamese data from Excel to Notepad with each column of row 1 as filename and each column of row 2 as content. However, when I open the Notepad file, the font was corrupted due to Unicode problem. (Notepad makes Ascii as default encoding). Please help me to edit the below code (which is from Internet source) with Unicode encoding to export the data. Thank you!

    Sub ExportToNotepad()
    Dim wsData As Variant
    Dim myFileName As String
    Dim FN As Integer
    Dim p As Integer, q As Integer
    Dim path As String
    Dim myString As String
    Dim lastrow As Long, lastcolumn As Long

    lastrow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
    lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    path = "D:\Jobs"

    For p = 1 To lastcolumn
    wsData = ActiveSheet.Cells(1, p).Value
    If wsData = "" Then Exit Sub
    myFileName = wsData
    myFileName = myFileName & ".txt"
    myFileName = path & myFileName
    MsgBox myFileName
    For q = 2 To lastrow
    myString = myString & " " & Cells(q, p)

    FN = FreeFile
    Open myFileName For Output As #FN
    Print #FN, myString
    Close #FN
    Next q
    myString = ""
    Next p

    End Sub

  2. #2
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,427

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,441

    Re: VBA: Export Vietnamese data from Excel to Notepad: Unicode problem

    here is a thread about saving text files in arabic

    http://www.vbforums.com/showthread.p...ght=arabic+BOM
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width