excel/vba 매크로의 Windows 상자에 플랫 파일로 유니 코드 문자열을 저장하고 싶습니다. 매크로는 일반 문자열을 유니 코드 표현으로 변환하고이를 파일에 저장하고 나중에 검색해야합니다.vba의 플랫 파일로 유니 코드 문자열
3
A
답변
2
"Microsoft Scripting Runtime"COM 구성 요소 (scrrun.dll)에 대한 참조를 추가하십시오.
파일을 만들거나 읽고 쓰는 데 필요한 모든 클래스 (특히 FileSystemObject/TextStream)가 있습니다.
5
언급 한 바와 같이 Microsoft Scripting Runtime (scrrun.dll)을 사용할 수 있습니다. 아래에 몇 가지 예를 게시했습니다. 어떤 사람들은 또한 네이티브 파일 입출력 기능을 좋아합니다. 여기에 광범위한 (쓰레드를 상당히 포괄적) 스레드가있다 : 그러나 http://www.xtremevbtalk.com/showthread.php?t=123814
유니 코드가 아마
Public Sub StringToTextFile(ByVal path As String, ByVal value As String)
'Requires reference to scrrun.dll
Dim fso As Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Set fso = New Scripting.FileSystemObject
Set ts = fso.CreateTextFile(path, False, True)
ts.Write value
ts.Close
End Sub
Public Sub LazyMansWay(ByVal path As String, ByVal value As String)
'Reference counting will cause the objects to be destroyed. The termination
'events of the classes will cause the connections to be closed.
CreateObject("Scripting.FileSystemObject").CreateTextFile(path, False, True).Write value
End Sub
1
내가 알 수있는 가장 좋은 방법은 문자열에서 읽어 Textstreams :)를 사용하는 것이 가장 고통스러운 파일에 대한 바이트 배열 및 바이너리 모드에서 파일을 열고 바이트 배열로 각 바이트를 판독하고 문자열로 변환하여이를 다시 읽어 진 파일
Private Function WriteBinaryFile(ByRef szData As String)
Dim bytData() As Byte
Dim lCount As Long
bytData = szData
Open PwdFileName For Binary As #1
For lCount = LBound(bytData) To UBound(bytData)
Put #1, , bytData(lCount)
Next lCount
Close #1
End Function
각 바이트 물품.
Sub ReadBinaryFile(ByRef gszData As String)
Dim aryBytes() As Byte
Dim bytInput As Byte
Dim intFileNumber
Dim intFilePos
intFileNumber = FreeFile
Open PwdFileName For Binary As #intFileNumber
intFilePos = 1
Do
Get #intFileNumber, intFilePos, bytInput
If EOF(intFileNumber) = True Then Exit Do
ReDim Preserve aryBytes(intFilePos - 1)
aryBytes(UBound(aryBytes)) = bytInput
intFilePos = intFilePos + 1
Loop While EOF(intFileNumber) = False
Close #intFileNumber
gszData = aryBytes
End Sub
+1 hd 포스트 품질 –