Results 1 to 2 of 2

Thread: long time issue with word doc

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    39

    long time issue with word doc

    I am trying to make a macro that would convert the input file to the output file. Please look at the attachments.

    The input file will vary in # of pages and sections. The sections will all begin similar to this:

    ( DIAMETER = 4. )
    ( CORNER RADIUS = .125 )
    ( STOCK ALLOWANCE = .03 )

    Essentially, I am trying to decrease the number of pages, for reference only. I would like each section to just fill up one page using the first 30 lines, 6 blank lines, and the last 20 lines. I would like the macro to print right away and then close the documents not saving anything.

    I have posted regarding this issue in the past but nothing is working and am not referring to those posts because I don't want to confuse anyone.

    I do have some code that kinda works and if that will help, let me know. I will post it.

    Any help would be appreciated.
    Attached Files Attached Files

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    39

    Re: long time issue with word doc

    here is the code I have. It works fine but won't put the last twenty lines of the last section into the output file because it is looking for a "(". This is where I am having my problem.

    VB Code:
    1. Sub YoYo()
    2.  
    3. Dim MyFile As Variant
    4. Dim OutputFile As String
    5. Dim count As Integer
    6. Dim LineArray() As String
    7. Dim MyLine As String
    8. Dim arrNum As Long
    9. Dim openfile As Long
    10. Dim temp As String
    11. Dim ALine, DeleteIt, lineNumberAtEnd, Last20Lines As Long
    12.  
    13. On Error GoTo MyErrorHandler:
    14.  
    15. ReDim LineArray(10000000#)             'This redimensions this array...I am assuming there is less than
    16.                                         '10000000 lines between tool sets.
    17. OutputFile = Mid$(CStr(ActiveDocument), 1, Len(ActiveDocument) - 3) & "doc"
    18. Open ActiveDocument For Input As #1
    19. Open OutputFile For Output As #2
    20.  
    21. 'Section 1--------------------------------------------------------------------------------------
    22.        
    23.        
    24.        'This first loop gets you past the header info before the first parentheses (
    25.  Line Input #1, MyLine                  'Initialize a line
    26. While InStr(1, MyLine, "%") = 0         'Until you find a ( just keep kicking out lines)
    27.  Print #2, MyLine
    28.  Line Input #1, MyLine
    29. Wend
    30.  
    31. arrNum = 1
    32.  
    33.  If InStr(1, MyLine, "%") <> 0 Then     'The first instance may or may not have lines
    34.   Print #2, MyLine                      'above it...this should be o.k.
    35.   For i = 1 To 30                       'Print 30 lines after the (
    36.    Line Input #1, MyLine
    37.    Print #2, MyLine
    38.   Next i
    39.  
    40.   For i = 1 To 6
    41.   Print #2,
    42.   Next i
    43.  
    44.     Line Input #1, MyLine
    45.    
    46.  
    47.   Do Until InStr(1, MyLine, "(") <> 0   'Until find another (, read lines into array
    48.    LineArray(arrNum) = MyLine
    49.    arrNum = arrNum + 1
    50.    Line Input #1, MyLine
    51.   Loop
    52.   If InStr(1, MyLine, "(") <> 0 Then
    53.    For i = 20 To 1 Step -1
    54.    Print #2, LineArray(arrNum - i)
    55.    Next i
    56.   End If
    57.   ReDim LineArray(10000000#)           'This just empties out the lines in the array
    58.   arrNum = 1
    59.  End If
    60.  
    61. 'SECTION 2-----------------------------------------------------------------------------------
    62.            
    63. While InStr(1, MyLine, "(") = 0         'Until you find a ( just keep kicking out lines)
    64.  Print #2, MyLine
    65. Wend
    66.  
    67. arrNum = 1
    68. While Not EOF(1)
    69.  If InStr(1, MyLine, "(") <> 0 Then     'The first instance may or may not have lines
    70.   Print #2, MyLine                      'above it...this should be o.k.
    71.   For i = 1 To 30                       'Print 30 lines after the (
    72.    Line Input #1, MyLine
    73.    Print #2, MyLine
    74.   Next i
    75.  
    76.   For i = 1 To 6
    77.   Print #2,
    78.   Next i
    79.  
    80.   Line Input #1, MyLine
    81.    
    82.  
    83.   Do Until InStr(1, MyLine, "(") <> 0  'Until find another (, read lines into array
    84.    LineArray(arrNum) = MyLine
    85.    arrNum = arrNum + 1
    86.    Line Input #1, MyLine
    87.   Loop
    88.   If InStr(1, MyLine, "(") <> 0 Then
    89.    For i = 20 To 1 Step -1
    90.    Print #2, LineArray(arrNum - i)
    91.    Next i
    92.   End If
    93. End If
    94. Wend
    95. 'SECTION 3----------------------------------------------------------------------------------------
    96.  
    97.  
    98.  
    99. Close #1
    100. Close #2
    101.  
    102. UserForm1.Hide
    103.  
    104. MyErrorHandler:
    105. If Err.number = 62 Then
    106.  Close #1
    107.  Close #2
    108.  'Set oDoc = Documents.Open(Path & OutputFile)
    109. 'With oDoc
    110. '  .PrintOut
    111. '  .Close SaveChanges:=False
    112. 'End With
    113. 'Set oDoc = Nothing
    114. End If
    115.  UserForm1.Hide
    116.  
    117. Exit Sub
    118. End Sub

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