Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I create text files with special characters in their filenames
    primarykey
    data
    text
    <p><em>Demonstration of my problem</em></p> <ul> <li>Open a new Excel workbook and save these symbols 設計師協會 to cell [A1]</li> <li>insert the following VBA code somewhere in the editor (<kbd>Alt</kbd>+<kbd>F11</kbd>)</li> <li>execute it line per line (<kbd>F8</kbd>)</li> </ul> <pre>Sub test() strCRLF = StrConv(vbCrLf, vbUnicode) strSpecialchars = StrConv(Cells(1, 1), vbUnicode) strFilename = "c:\test.txt" Open strFilename For Output As #1 Print #1, strSpecialchars & strCRLF; Close #1 End Sub</pre> <p>You will get a textfile which contains the chinese characters from [A1]. This proofs that VBA is able to handle unicode characters if you know the trick with adding <code>StrConv(vbCrLf, vbUnicode) </code></p> <p>Now try the same for <code>strFilename = "C:\" &amp; strSpecialchars &amp; ".txt"</code>. You will get an error that you can't create a file with this filename. Of course you can't use the same trick adding a new line since its a filename.</p> <p>How can I create text files with special characters in their filenames using VBA?<br> Is there a work-around or am I doing something wrong?</p> <p><strong>Note</strong></p> <ul> <li>I'm using Windows 7 x64. I'm able to create text files with special characters manually</li> <li>I found a <a href="http://www.excelforum.com/excel-programming-vba-macros/394470-write-line-problem-when-writing-simplified-chinese-characters.html?p=1060414&amp;viewfull=1" rel="nofollow noreferrer">second method using FileSystemObject</a>. But I hope I could avoid setting a reference <a href="https://stackoverflow.com/questions/3233203/how-do-i-use-filesystemobject-in-vba">to the VB script run-time library</a></li> </ul>
    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.
 

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