[英]How to insert, through VBA, a formula in a cell with special characters like “-” or “$”?
[英]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:
这是我尝试过的并且有效的...
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.