Here is my code:
Private Sub CommandButton1_Click()
filopn1 = Application.GetOpenFilename("Text Files (*.prg), *.prg*")
If filopn1 = "" Then
MsgBox "Please select a file"
Exit Sub
End If
If UCase(Right(filopn1, 3)) <> "PRG" Then
MsgBox "This app only good for text files"
Exit Sub
End If
TextBox1.Text = filopn1
Call Make_Sections(filopn1)
End Sub
Sub Make_Sections(MyFile As Variant)
Dim OutputFile As String
Dim count As Integer
Dim MyLine As String
OutputFile = Mid$(CStr(MyFile), 1, Len(MyFile) - 3) & "doc"
Open MyFile For Input As #1
Open OutputFile For Output As #2
While Not EOF(1)
Line Input #1, MyLine
If InStr(1, MyLine, "(" - 10) <> 0 Then
Print #2, MyLine
For i = 1 To 56
Line Input #1, MyLine
Print #2, MyLine
Next i
End If
Wend
Close #1
Close #2
UserForm1.Hide
End Sub
This starts automatically when I start a certain excel file, has an "open file" button from which I select a document, it creates a word doc. in the format I want it. The original document, which varies, is upwards of a few hundred pages long. This code shortens it to a few pages with certain info. that is needed.
I would like to put this in Word and use it as a macro for the current open document but can't get it to work. Could someone please help me.
Private Sub CommandButton1_Click()
filopn1 = Application.GetOpenFilename("Text Files (*.prg), *.prg*")
If filopn1 = "" Then
MsgBox "Please select a file"
Exit Sub
End If
If UCase(Right(filopn1, 3)) <> "PRG" Then
MsgBox "This app only good for text files"
Exit Sub
End If
TextBox1.Text = filopn1
Call Make_Sections(filopn1)
End Sub
Sub Make_Sections(MyFile As Variant)
Dim OutputFile As String
Dim count As Integer
Dim MyLine As String
OutputFile = Mid$(CStr(MyFile), 1, Len(MyFile) - 3) & "doc"
Open MyFile For Input As #1
Open OutputFile For Output As #2
While Not EOF(1)
Line Input #1, MyLine
If InStr(1, MyLine, "(" - 10) <> 0 Then
Print #2, MyLine
For i = 1 To 56
Line Input #1, MyLine
Print #2, MyLine
Next i
End If
Wend
Close #1
Close #2
UserForm1.Hide
End Sub
This starts automatically when I start a certain excel file, has an "open file" button from which I select a document, it creates a word doc. in the format I want it. The original document, which varies, is upwards of a few hundred pages long. This code shortens it to a few pages with certain info. that is needed.
I would like to put this in Word and use it as a macro for the current open document but can't get it to work. Could someone please help me.