Script to extract the first 30 characters of each line from a file
Hello,
I have a word document that is 145 pages. I only need the first 30 characters of each line. Is there any way to have a script scan the file and either extract the first 30 characters of each line and create a new file or delete the rest from each line?
Thank you
VB ScriptVisual Basic Classic
Last Comment
Martin Liss
8/22/2022 - Mon
Martin Liss
Try this but it may not work because of the encoding that Word does. If you go into Word and save the doc as a text file I think it will work.
Dim FF As Integer
Dim FF2 As Integer
Dim strLine As String
FF = FreeFile
Open "C:\temp\test.doc" For Input As #FF
FF2 = FreeFile
Open "C:\temp\temp.doc" For Output As #FF2
Do While Not EOF(FF)
Line Input #FF, strLine
If Len(strLine) > 29 Then
strLine = Left$(30, strLine)
End If
Print #FF2, strLine
Loop
Close
Patrick Matthews
I have a word document that is 145 pages. I only need the first 30 characters of each line.
Define "line". There is no such object in Word.
Indeed, since different print drivers can render printed text differently, the whole concept of a "line" of text does not make much sense.
Did you perhaps mean "I only need the first 30 characters of each paragraph"?
Dim FF As Integer
Dim FF2 As Integer
Dim strLine As String
FF = FreeFile
Open "C:\temp\test.doc" For Input As #FF
FF2 = FreeFile
Open "C:\temp\temp.doc" For Output As #FF2
Do While Not EOF(FF)
Line Input #FF, strLine
If Len(strLine) > 29 Then
strLine = Left$(30, strLine)
End If
Print #FF2, strLine
Loop
Close