[Solved] How to replace comma with space in text file using VBA [closed]


This should do the trick:

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

3

solved How to replace comma with space in text file using VBA [closed]