我已经实现了一个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
P.S。对于unicode中这些字符的列表,我希望使用ASCII:
答案 0 :(得分:1)
这是我尝试过的,它有效...
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