我在文本文件中有数据(input.jpg)。我想用空格替换逗号并将数据对齐到一行。请看输出文本文件(output.jpg)。
如何在VBA中执行此操作。 请帮帮我。
[输入数据]
答案 0 :(得分: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