PDA

Click to See Complete Forum and Search --> : [RESOLVED] Delete the first two lines of a word Doc.


wooonelly
Mar 2nd, 2006, 11:36 AM
I am using a Word Macro that edits an open document by keeping the first 30 lines and last ten lines of a section for as many sections there are in a document then creates a new doc. Each section is marked by a "(" and this is what the code uses to find the sections.

The problem is that at the beginning of the document I have two lines before the first "(" and this throws off the document by two lines. I want each section to make up 1 page. If I change the numbers two make the first page look all right, the rest of the doc. gets screwed up.

I would like to delete the first two lines of the ActiveDocument and then the macro to work from there. I have tried ranges and selections to delete the first two lines and can't get it to work.

Here is the code:

Sub YoYo()

Dim MyFile As Variant
Dim OutputFile As String
Dim count As Integer
Dim LineArray() As String
Dim MyLine As String
Dim arrNum As Long
Dim openfile As Long
Dim temp As String
Dim ALine, DeleteAt As Long



On Error GoTo MyErrorHandler:

ReDim LineArray(10000000#)
OutputFile = Mid$(CStr(ActiveDocument), 1, Len(ActiveDocument) - 3) & "doc"
Open ActiveDocument For Input As #1
Open OutputFile For Output As #2




Line Input #1, MyLine
While InStr(1, MyLine, "(") = 0
Print #2, MyLine
Line Input #1, MyLine
Wend

arrNum = 1
While Not EOF(1)
If InStr(1, MyLine, "(") <> 0 Then
Print #2, MyLine
For i = 1 To 30
Line Input #1, MyLine
Print #2, MyLine
Next i

For i = 1 To 6
Print #2,
Next i

Line Input #1, MyLine


Do Until InStr(1, MyLine, "(") <> 0
LineArray(arrNum) = MyLine
arrNum = arrNum + 1
Line Input #1, MyLine
Loop
If InStr(1, MyLine, "(") <> 0 Then
For i = 20 To 1 Step -1
Print #2, LineArray(arrNum - i)
Next i
End If
ReDim LineArray(10000000#)
arrNum = 1
End If
Wend

Close #1
Close #2

UserForm1.Hide

MyErrorHandler:
If Err.number = 62 Then
Close #1
Close #2
'Set oDoc = Documents.Open(Path & OutputFile)
'With oDoc
' .PrintOut
' .Close SaveChanges:=False
'End With
'Set oDoc = Nothing
End If
UserForm1.Hide

Exit Sub


End Sub


here is a sample of the beginning of the doc:

%
O0001
( DIAMETER = .5 )
( CORNER RADIUS = .031 )
( STOCK ALLOWANCE = 0 )
G91 G28 Z0
H0 G49
T1
M6
G90
M3 S2500
G5 P1
G61.1
G0 X0 Y.0785
G43 Z-1.4 H1 M50
X.4685 Y-.8716
Z-1.9
G1 Z-2.003 F70......this goes on for hundreds of lines

The second and rest of the sections all start the same way without the "%" and O0001 lines. These are the two lines I would like to delete before the macro runs. The new document does not need to be saved.

Any help is appreciated.

Killazzz
Mar 2nd, 2006, 01:59 PM
Hello,

Why don't you just start reading at line 3

Just do 2 line input before writing. And indent your code for readability. thanks


Line Input #1, MyLine
Line Input #1, MyLine
' this part checks for ( not being in the input, but why ?
While InStr(1, MyLine, "(") = 0
Print #2, MyLine
Line Input #1, MyLine
Wend

wooonelly
Mar 2nd, 2006, 02:20 PM
Thank You that is what I was looking for.Sorry about the format, I am new to this.