Я хочу сохранить строку unicode в плоском файле в окне окна из макроса excel/vba. Макрос преобразует нормальную строку в представление юникода, необходимо сохранить ее в файле и получить позже.Unicode string to flat file from vba
ответ
Добавить ссылку на COM-компонент Microsoft Scripting Runtime (scrrun.dll).
Он имеет все классы (в частности, FileSystemObject/TextStream) для создания/чтения/записи файлов.
Как уже упоминалось, вы можете использовать Microsoft Scripting Runtime (scrrun.dll). Я привел несколько примеров ниже. Некоторым людям также нравятся функции IO собственного файла. Существует обширная (и достаточно полный Thread) здесь: http://www.xtremevbtalk.com/showthread.php?t=123814
Однако для Unicode файлов это, вероятно, наименее болезненным для использования Textstreams :)
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
Лучшее решение, которое я мог понять, читается строка в в массив байтов и записи каждого байта в двоичный файл
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
Read его назад, открыв файл в двоичном режиме и чтения каждый байт в массив байтов, а затем преобразовать его в строку.
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. oracle to flat file
- 2. Flat FILE to XML и vica versa
- 3. Java String to unicode
- 4. VBA Open File From Hyperlink
- 5. Unicode to string
- 6. Python unicode dictornary to string from twitch stream
- 7. Interpolate String Loaded From File
- 8. Informatica flat file
- 9. from string to number xslt
- 10. print to file from C#
- 11. unicode flat file не может найти разделитель строк CRLF
- 12. SSIS Flat File Source
- 13. SSIS Flat File Unpivot
- 14. Flat File Schema Wizard
- 15. String Dict to Unicode conversion
- 16. Javascript: Unicode string to hex
- 17. iOS encode string to unicode
- 18. File Write: String to Bytes
- 19. Convert Ansible variable from Unicode to ASCII
- 20. Ruby Convert String to File
- 21. Laravel string to file limit
- 22. Parse String Array to FIle
- 23. Hashtable to string/JSON file
- 24. Ruby File to String Issues
- 25. PHP regex replace from string to string
- 26. String from bufferedReader to arraylist
- 27. Covert from String to SHA256
- 28. Regexp to и from string
- 29. VB.net from string to bitmap
- 30. Reformat From String to Decimal
+1 hd качество сообщения –