繁体   English   中英

通过VBA在ANSII中的特殊字符

[英]Special characters in ANSII through VBA

我已经实现了一个vba脚本,该脚本创建文件夹,文件,并在每一行的文件中放入描述。 问题是塞尔维亚拉丁字母,例如“š,đ,č,ć,ž”。 由于另一个程序,文件必须记录在ANSII .txt文件中。更尴尬的是,第一个文件以.txt(ANSII编码)是可以的,并且保留čćšđš字母,但其他文件则不能。

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

在此链接上,我上传了测试文件: 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Č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

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM