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:
VB 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, "(") <> 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.




Reply With Quote