excel/vbaマクロのウィンドウボックスにフラットファイルとしてユニコード文字列を格納したい。マクロは通常の文字列をUnicode表現に変換し、ファイルに格納して後で取得する必要があります。vbaからフラットファイルへのUnicode文字列
3
A
答えて
2
「Microsoft Scripting Runtime」COMコンポーネント(scrrun.dll)への参照を追加します。
ファイルを作成/読み書きするためのすべてのクラス(具体的にはFileSystemObject/TextStream)があります。
5
前述のとおり、Microsoft Scripting Runtime(scrrun.dll)を使用することができます。私はいくつかの例を以下に掲載しました。また、ネイティブのファイルIO機能が好きな人もいます。ここでは大規模な(そしてかなり包括的なスレッド)スレッドがあります: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
1
私が理解できた最善の解決策は、文字列を読み込まれるファイルのためのバイト配列とバイナリファイルへの各バイトを書き込む
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. Excel VBA文字列のUnicode文字を削除する
- 2. ExcelのVBAマクロのUnicode文字?
- 3. numpy文字列から文字列へ
- 4. Unicode文字列リテラル
- 5. 文字列Unicode文字列から文字を削除します。
- 6. urllib.requestのUnicode文字列
- 7. から文字列へ
- 8. PDfから文字列へ
- 9. DataTableから文字列へ
- 10. javaからxmlへのUnicode文字の受け渡し
- 11. エクセル/ VBA:文字列
- 12. ルビー:アンエスケープUnicode文字列
- 13. 文字列から文字列へのマップの述語
- 14. spring mvc form bean文字列から文字列への変換
- 15. 文字列へのポインタから文字列をコピー
- 16. C++、文字列から文字配列への変換
- 17. Android文字列から配列へ
- 18. PythonのUnicode文字列から改行文字を削除する問題
- 19. Pythonの:Unicodeから文字列の複雑な辞書が
- 20. 文字列1から文字列2への文字の置換
- 21. Dozer Converterマップ文字列から文字列へ
- 22. R.id.imageからandroidの文字列へ
- 23. io.ReaderからGoの文字列へ
- 24. 文字列[]からAndroidのListViewへ
- 25. GZipStreamからgzipへの文字列
- 26. 文字列からintへの変換
- 27. 文字列からバイトへの変換
- 28. Java:inetaddressから文字列への変換
- 29. はDjangoのUnicodeエンコーディングから文字列を抽出
- 30. TWebRequestのコンテンツフィールドからUnicode文字列を読み取る
+1 hdポストクオリティ –