title: How to save .txt as Unicode or UTF-8 in VBA
body: <p>I want that all my files be saved in unicode or utf-8 format and not ANSI.</p>
  <p>Here is the code:</p>
  <pre><code>Sub cvelle()
  Dim iRow As Long
  Dim iFile As Integer
  Dim sPath As String
  Dim sFile As String
  
  
  For iRow = 1 To Cells(Rows.Count, &quot;B&quot;).End(xlUp).Row
      iFile = FreeFile
      With Rows(iRow)
          sPath = &quot;E:\&quot; &amp; .Range(&quot;B1&quot;).Value &amp; &quot;\&quot;
          If Len(Dir(sPath, vbDirectory)) = 0 Then MkDir sPath
          sFile = .Range(&quot;D1&quot;).Value &amp; &quot;.txt&quot;
          
          Open sPath &amp; sFile For Output As #iFile
          Print #iFile, .Range(&quot;E1&quot;).Value
          Close #iFile
      End With
  Next iRow
  End Sub
  </code></pre>
  <p>Now, I thought that just inserting the code below would be enough.</p>
  <pre><code>sFile = .Range(&quot;D1&quot;).Value &amp; &quot;.txt&quot;,FileFormat:= _xlUnicodeText
  </code></pre>
  <p>But it gives me an error.</p>