PDA

Click to See Complete Forum and Search --> : Excel --> Word Macro


wooonelly
Feb 22nd, 2006, 03:11 PM
I have this code that was created in Excel as a macro. I would like this to be a macro in Word and can't get it to run properly. It works great in Excel.
Here it is:

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, "(") <> 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 code takes a multi page NC Code seperated by sections labeled like this, (Section1), and creates a document that was 100 pages with 5 sections to be only 5 pages long and start each page with each section.

Could someone please help me convert this.

Comintern
Feb 22nd, 2006, 05:57 PM
I'm not quite sure what you are after here. Do you want to create a word document instead of a text file? It might help to see a sample of the input file and a sample of the expected output. I'm also not sure of what you mean by reducing the page count from 100 to 5. Text files don't have page breaks unless they are padded out with newlines to 'format' them.