Code:
'vFieldArray contains field lengths, in characters, from field 1 to BH
vFieldArray = Array(1, 1, 12, 6, 6, 12, 12, 11, 3, 12, 12, 12, 12, 12, 1, 20, 12, 1, 1, 3, 1, 12, 20, 11, 20, 7, 20, 11, 1, 12, 12, 12, 12, 1, 20, 12, 12, 12, 1, 50, 12, 75, 1, 1, 12, 6, 6, 9, 6, 6, 12, 5, 35, 1, 50)
nFileNum = FreeFile
Open "C:\Documents and Settings\All Users\Desktop\ordtemp." For Output As #nFileNum
For Each myRecord In Range("A8:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For i = 0 To 41
sOut = sOut & DELIMITER & Left(.Offset(0, i).Text & _
String(vFieldArray(i), PAD), vFieldArray(i))
Next i
Print #nFileNum, Mid(sOut, Len(DELIMITER) + 1)
sOut = Empty
For i = 42 To UBound(vFieldArray)
sOut = sOut & DELIMITER & Left(.Offset(0, i).Text & _
String(vFieldArray(i), PAD), vFieldArray(i))
Next i
Print #nFileNum, Mid(sOut, Len(DELIMITER) + 1)
sOut = Empty
End With
Next myRecord
Close #nFileNum
' Open our source file
f1 = FreeFile
Open "C:\Documents and Settings\All Users\Desktop\ordtemp." For Input As #f1
' Open our target file
f2 = FreeFile
Open "C:\Documents and Settings\All Users\Desktop\ord." For Output As #f2
' Start processing till we reach the end
Do While Not EOF(f1)
' Read a line from the source file
Line Input #f1, x
' And if the line isn't empty, write it to the target file
If x <> " " Then
If x <> " " Then
Print #f2, x
End If
End If
Loop
' Close the two opened files
Close #f2
Close #f1
'Delete the unecessary temp file
strFile = "C:\Documents and Settings\All Users\Desktop\ordtemp."
Set fs = CreateObject("Scripting.FileSystemObject")
fs.deletefile strFile
'This formats name of the text file to be ord.YYYYMMDDHHMI
OldFile1 = "C:\Documents and Settings\All Users\Desktop\ord."
newfile1 = Format(Now, "yyyymmddhhmmss")
newfile1 = OldFile1 & newfile1
Name OldFile1 As newfile1