Hi there,
I know how to clear the blank spaces from a text file and how to get the amount of characters in my text file. However, I would like to be able to extract a word which change every time I create my text file.
Any ideas?
Thank You in advance,
Read in the file with one command. I use the FileSystemObject.
Dim strFileData As string
Dim strFileIn As String
strFileIn = "C:\In.txt"
strFileOut = "C:\Out.txt"
strFileData = ReadProto(strFileIn)
strFileData = Replace(strFileData,"MyWord","NewWord",vbTextCompare)
WriteProto strFileOut, strFileData, ForWriting
Private Function ReadProto(strFileName As String) As String
Dim objFS As FileSystemObject
Dim objTS As TextStream
Set objFS = New FileSystemObject
Set objTS = objFS.OpenTextFile(strFileName, _
ForReading, False, TristateFalse)
ReadProto = objTS.ReadAll
objTS.Close
Set objTS = Nothing
Set objFS = Nothing
End Function
Private Sub WriteProto(strFileName As String, _
strOut As String, _
lngIoMode As IOMode)
Dim objFS As FileSystemObject
Dim objTS As TextStream
Set objFS = New FileSystemObject
Set objTS = objFS.OpenTextFile(strFileName, _
lngIoMode, True, TristateFalse)
objTS.Write strOut
objTS.Close
Set objTS = Nothing
Set objFS = Nothing
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.