2017-12-06 6 views
-4

テキストファイル(input.jpg)にデータがあります。コンマをスペースに置き換え、データを1行に整列させたいと思います。出力テキストファイル(output.jpg)を見てください。VBAを使用してテキストファイルのカンマをスペースに置き換える方法

VBAでこれを行う方法。 私を助けてください。

[入力データ] enter image description here

+1

スタックオーバーフローがないコードのサイトに私を教えています。あなたが動作しないコードをお持ちの場合は、[編集]を使用して元の投稿に投稿し、エラーの発生箇所を正確に説明してください。 –

+0

Windowsを使用している場合。これを行うにはPowerShellが適しているかもしれません:https://blogs.technet.microsoft.com/heyscriptingguy/2008/01/17/hey-scripting-guy-how-can-i-use-windows-powershell-to-テキストファイルを置換する/ –

答えて

0

これはトリックを行う必要があります。

Sub foo() 
Dim objFSO 
Const ForReading = 1 
Const ForWriting = 2 
Dim objTS 'define a TextStream object 
Dim strContents As String 
Dim fileSpec As String 

fileSpec = "C:\Test.txt" 'change the path to whatever yours ought to be 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objTS = objFSO.OpenTextFile(fileSpec, ForReading) 

Do While Not objTS.AtEndOfStream 
    strContents = strContents & " " & objTS.ReadLine 'Read line by line and store all lines in strContents 
Loop 

strContents = Replace(strContents, ",", " ") 
objTS.Close 

Set objTS = objFSO.OpenTextFile(fileSpec, ForWriting) 
objTS.Write strContents 
objTS.Close 
End Sub 
+0

ありがとうXabier。それは働いている。 – chandrashekar

+0

データがテキストファイル内の複数の行にある場合は、1行に並べる方法。例:「Datastart 19A 56 1 0x1112 0x1314 0x1516 0x1718 0x1920 0x2122 0x2324 0x2526 0x2728 0x2930 0x3132 0x3334 0x3536 0x3738 0x3940 0x4362 0x4344 0x4546 0x4748 0x4950 0x5152 0x5354 0x5556 0x5758 0x5960 0x6662 0x6364 0x6566 "。このテキストをどのように1行に並べるか – chandrashekar

+0

@chandrashekar私はすべての行を1行にする答えを更新しました。 – Xabier

関連する問題