title: Reading International/Special Characters in VBA
body: <p>I read an Excel spreadsheet row by row and for each row create a textfile including information from the columns.</p>
  
  <p>From time to time there is foreign text in some of the spreadsheet cells. In the debugger the foreign text appears as '?' question marks. It fails when trying to write these question marks to the text file.</p>
  
  <p>This is a snippet of the code that reads the values from a row to a string array</p>
  
  <pre><code>    Set oFS = CreateObject("Scripting.Filesystemobject")
      For Each rID In oSh.UsedRange.Columns("A").Cells
          For Each rValue In oSh.UsedRange.Rows(rowCount).Cells
              ReDim Preserve columnValues(columnCount)
              columnValues(columnCount) = rValue
              columnCount = columnCount + 1
          Next
      Next
  </code></pre>
  
  <p>This is the code which writes to a text file</p>
  
  <pre><code>sFNText = sMakeFolder &amp; "\" &amp; rID.Value &amp; ".txt"
  Set oTxt = oFS.OpenTextFile(sFNText, 2, True)
  
  For i = 0 To UBound(columnTitles)
       oTxt.Write columnTitles(i) &amp; ": " &amp; columnValues(i) &amp; vbNewLine
  Next i
  
  oTxt.Close
  </code></pre>
  
  <p>I have experimented with changing the format of opentextfile and also using AscW and ChrW to convert to and from ansi.</p>
  
  <p>EDIT: In particular I am trying to read in Greek symbols (pi, omega etc.) and write them back out to a textfile.  I have used the </p>
  
  <pre><code>StrConv(Cells(1, 1), vbUnicode)
  </code></pre>
  
  <p>method that was detailed in <a href="https://stackoverflow.com/questions/14261632/how-can-i-create-text-files-with-special-characters-in-their-filenames">How can I create text files with special characters in their filenames</a> and have got that example working. It seems now a problem with writing this to a textfile. nixda's example seems to work in isolation when using his Print command, however when I try</p>
  
  <pre><code>otxt.Write
  </code></pre>
  
  <p>to write my stored variable to a textfile it writes out garbage, as opposed to the print method which produces the correct result.  Looking at the debugger both variables are stored identically (print method + write), so I believe it is now down to the output method (otxt.Write) which is converting the stored variable into garbage.  I have tried using the -1 &amp; -2 options for OpenTextFile - both producing garbage results.</p>