ANSII中的特殊字符通过VBA

我已经实现了一个vba脚本来创build文件夹,文件,并把每个行的文件中的描述。 问题是塞尔维亚拉丁字母,如“š,đ,č,ć,ž”。 文件必须logging在ANSII .txt文件中,因为另外一个程序。更尴尬的是,第一个文件在.txt(ANSII编码)中是可以的,它保留了字母,但是其他的都不行。

也许我需要更改控制面板中的键盘设置?

在这个链接上我已经上传了testing文件: File

请运行这个简单的代码,请给我任何反馈。 谢谢!

Sub files() Dim iRow As Long Dim iFile As Integer Dim sPath As String Dim sFile As String For iRow = 1 To Cells(Rows.Count, "C").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 

PS在unicode中的这些字符的列表,我想要在ASCII:

  • U + 0106Ć0xC4 0x86 \ 304 \ 206Ć
  • U + 0107℃0xC4 0x87 \ 304 \ 207℃
  • U + 010C 0x 0xC4 0x8C \ 304 \ 214Č
  • U + 010Dč0xC4 0x8D \ 304 \ 215č
  • U + 0110□0xC4 0x90 \ 304 \ 220□
  • U + 0111□0xC4 0x91 \ 304 \ 221□
  • U + 0160Š0xC5 0xA0 \ 305 \ 240Š
  • U + 0161š0xC5 0xA1 \ 305 \ 241š
  • U + 017DŽ0xC5 0xBD \ 305 \ 275Ž
  • U + 017E×0xC5 0xBE \ 305 \ 276

这是我试过的,它的工作原理

 Sub files() Dim iRow As Long Dim sPath As String, sFile As String Dim fs As Object Set fs = CreateObject("Scripting.FileSystemObject") For iRow = 2 To Cells(Rows.Count, "C").End(xlUp).Row sPath = "E:\" & Range("B1").Value & "\" If Len(Dir(sPath, vbDirectory)) = 0 Then MkDir sPath sFile = Range("D" & iRow).Value & ".txt" With fs With .CreateTextFile(sPath & sFile, , True) .Write Range("E" & iRow).Value .Close End With End With Next iRow End Sub 

在这里输入图像说明