【发布时间】:2015-06-19 08:04:03
【问题描述】:
我希望我的所有文件都保存为 unicode 或 utf-8 格式,而不是 ANSI。
代码如下:
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, "B").End(xlUp).Row
iFile = FreeFile
With Rows(iRow)
sPath = "E:\" & .Range("B1").Value & "\"
If Len(Dir(sPath, vbDirectory)) = 0 Then MkDir sPath
sFile = .Range("D1").Value & ".txt"
Open sPath & sFile For Output As #iFile
Print #iFile, .Range("E1").Value
Close #iFile
End With
Next iRow
End Sub
现在,我认为只需插入下面的代码就足够了。
sFile = .Range("D1").Value & ".txt",FileFormat:= _xlUnicodeText
但它给了我一个错误。
【问题讨论】:
-
使用
FileSystemObject,例如see here。 -
在stackoverflow.com/questions/12352958/excel-vba-export-to-utf-8 上有一篇精彩的帖子,它绕过了 Excel 的 mongrel unicode 导出并通过 ODBC 使用真正的 Utf-8
-
谢谢!我去看看!
-
只是为了确保我们都在同一个页面上,我想在 .txt 中插入的文本已经是 unicode,我只想在记事本中设置默认 SavaAs type= unicode..因为那里是丢失了一些字符.. 谢谢!