srinivassurapareddi
New Member
- Joined
- Sep 23, 2015
- Messages
- 1
Hi There! I wanted to parse a text file searching for text "$$$$$" and append some come content at the end og the line where the text is found.
example:
input file:
Hi there! you read this msg
$$$$$ 1234,2345
output file:
Hi there! you read this msg
$$$$$ 1234,2345,6479
Added 6479 (default content). i wanted to do the same for all files in the folder. but this is sample i wanted to do. I could able to read line by line.
#
Sub start()
Dim FP As String, nFile As String, textline As String, pos As Integer
Dim flag As Boolean
Dim files As Variant
flag = True
'Get the folder path in string
FP = Application.ActiveWorkbook.Path
FP = FP & "\"
files = Dir(FP & "*.txt", vbNormal)
'loop for all files
While flag = True
If files = "" Then GoTo 0
nFile = FP & files
Open nFile For Input As #1
'text parser
Do Until EOF(1)
Line Input #1, textline
pos = InStr(textline, "$$$$$")
If pos <> 0 Then
textline = textline & ",6479"
Print #1, textline
End If
Loop
Close #1
files = Dir
Wend
0: Exit Sub
End Sub
#
i can not read and write the same time. I do not know i to use append!
Please help me
Regards,
Srini
example:
Code:
Hi there! you read this msg
$$$$$ 1234,2345
output file:
Hi there! you read this msg
$$$$$ 1234,2345,6479
Added 6479 (default content). i wanted to do the same for all files in the folder. but this is sample i wanted to do. I could able to read line by line.
#
Sub start()
Dim FP As String, nFile As String, textline As String, pos As Integer
Dim flag As Boolean
Dim files As Variant
flag = True
'Get the folder path in string
FP = Application.ActiveWorkbook.Path
FP = FP & "\"
files = Dir(FP & "*.txt", vbNormal)
'loop for all files
While flag = True
If files = "" Then GoTo 0
nFile = FP & files
Open nFile For Input As #1
'text parser
Do Until EOF(1)
Line Input #1, textline
pos = InStr(textline, "$$$$$")
If pos <> 0 Then
textline = textline & ",6479"
Print #1, textline
End If
Loop
Close #1
files = Dir
Wend
0: Exit Sub
End Sub
#
i can not read and write the same time. I do not know i to use append!
Please help me
Regards,
Srini