Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Value retrieved from the cell is already in Unicode.</p> <p><code>StrConv(vbUnicode)</code> gives you "double unicode" which is broken because it went through a conversion using the current sustem codepage.<br> Then the <code>Print</code> command converts it back to "single unicode", again using the current system codepage. Don't do this. You're not saving unicode, you're saving invalid something that may only appear valid on your particular computer under your current settings.</p> <p>If you want to output Unicode data (that is, avoid the default VB mechanism of auto-converting output text from Unicode to ANSI), you have several options.</p> <p>The easiest is using <code>FileSystemObject</code> without trying to invent anything about unicode conversions:</p> <pre><code>With CreateObject("Scripting.FileSystemObject") With .CreateTextFile("C:\" &amp; Cells(1).Value &amp; ".txt", , True) .Write Cells(1).Value .Close End With End With </code></pre> <p>Note the last parameter that controls Unicode.</p> <p>If you don't want that, you can declare <code>CreateFileW</code> and <code>WriteFile</code> functions:</p> <pre><code>Private Declare Function CreateFileW Lib "kernel32.dll" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long Private Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, ByRef lpNumberOfBytesWritten As Long, ByRef lpOverlapped As Any) As Long Private Const CREATE_ALWAYS As Long = 2 Private Const GENERIC_WRITE As Long = &amp;H40000000 </code></pre> <pre><code>Dim hFile As Long hFile = CreateFileW(StrPtr("C:\" &amp; Cells(1).Value &amp; ".txt"), GENERIC_WRITE, 0, ByVal 0&amp;, CREATE_ALWAYS, 0, 0) Dim val As String val = Cells(1).Value WriteFile hFile, &amp;HFEFF, 2, 0, ByVal 0&amp; 'Unicode byte order mark (not required, but to please Notepad) WriteFile hFile, ByVal StrPtr(val), Len(val) * 2, 0, ByVal 0&amp; CloseHandle hFile </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload