Results 1 to 2 of 2

Thread: Excel --> Word Macro

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    39

    Excel --> Word Macro

    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:
    1. Private Sub CommandButton1_Click()
    2.  
    3. filopn1 = Application.GetOpenFilename("Text Files (*.prg), *.prg*")
    4. If filopn1 = "" Then
    5.  MsgBox "Please select a file"
    6.  Exit Sub
    7. End If
    8.  
    9. If UCase(Right(filopn1, 3)) <> "PRG" Then
    10.  MsgBox "This app only good for text files"
    11.  Exit Sub
    12. End If
    13.  
    14. TextBox1.Text = filopn1
    15. Call Make_Sections(filopn1)
    16.  
    17. End Sub
    18. Sub Make_Sections(MyFile As Variant)
    19. Dim OutputFile As String
    20. Dim count As Integer
    21. Dim MyLine As String
    22.  
    23. OutputFile = Mid$(CStr(MyFile), 1, Len(MyFile) - 3) & "doc"
    24. Open MyFile For Input As #1
    25. Open OutputFile For Output As #2
    26.  
    27. While Not EOF(1)
    28.  Line Input #1, MyLine
    29.  If InStr(1, MyLine, "(") <> 0 Then
    30.   Print #2, MyLine
    31.   For i = 1 To 56
    32.    Line Input #1, MyLine
    33.    Print #2, MyLine
    34.   Next i
    35.  End If
    36. Wend
    37.  
    38. Close #1
    39. Close #2
    40. UserForm1.Hide
    41.  
    42. 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.
    Last edited by RobDog888; Feb 22nd, 2006 at 04:18 PM. Reason: Added [vbcode] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width