Link to home
Start Free TrialLog in
Avatar of cbones
cbonesFlag for United States of America

asked on

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
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

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
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"?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cbones

ASKER

I am not able to get this script to work.  I will try it again.
What happens when you try it?
Avatar of cbones

ASKER

I recieve

line 2
char 8
expected end of statement
Please attach the file that you are trying to read.