Results 1 to 2 of 2

Thread: Excel --> Word Macro

  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

  2. #2
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Excel --> Word Macro

    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.

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