Sub openFile()
'
' openFile Macro
' Macro recorded 5/28/2003 by jojo_r
Dim data As String
On Error GoTo ErrorTrap
Open Cells(1, 2) For Input As #1
Open Cells(2, 2) For Output As #2
' Open Cells(3, 2) For Output As #3
Dim myArray As Variant
Dim ctr As Integer
ReDim myArray(1 To 20) As Variant
Dim strTot As Double
strTot = 0
r = 5
strtemp = ""
transref = 1
xcntr = 0
Cells(3, 2) = 0
Cells(3, 4) = 0
strordering = Cells(4, 2)
strAccntNo = "200285018"
Dim strtemp1 As String
Do While Not EOF(1)
For ctr = 1 To 20
Line Input #1, myArray(ctr)
If EOF(1) Then
Exit For
End If
Next ctr
ctr2 = 1
Do Until ctr2 = ctr + 1
strtemp1 = Trim(Mid(myArray(ctr2), 91, 8))
If strtemp1 = Trim(Mid(myArray(ctr2), 91, 8)) Then
strbene = Trim(Mid(myArray(ctr2), 51, 40))
strnetamt1 = Trim(Mid(myArray(ctr2), 172, 15))
trans_ref = Trim(Mid(myArray(ctr2), 91, 8))
strdelmet = ReturnDeliveryMethod
Cells(6, 14) = strbene
strTot = strTot + strnetamt1
ctr2 = ctr2 + 1
Else
strLine = "PLC@" & "PH@" & _
strAccntNo & "@" & "PHP" & "@" & Format(strTot, "###0.#0") & "@@" & Format(Now, "MMDDYYYY") & "@" & Format(trans_ref, "00000000") & "@@" & "@@@" & "@" & _
strordering & "@@@@@@" & strbene & "@." & "@" & "@@@@" & "@" & "@@@@@@" & "@" & "@" & "@" & "@@@@@@@@@@@@@@@@@@@@@@@@@@" & _
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" & strdelmet & "@@@@@@@@@@@@@@@@@@@@@@@"
Cells(3, 2) = strTot 'strnetamt1 + Cells(3, 2)
Print #2, RplChar(strLine, "^", " ")
xcount = 1
'If Trim(Mid(data, 99, 1)) <> "" Then
Do Until xcount = ctr2
invoiceLine = Trim(Mid(myArray(xcount), 99, 25))
invoiceLine2 = Trim(Mid(myArray(xcount), 124, 8))
invoiceLine3 = Trim(Mid(myArray(xcount), 132, 30))
strLine = "INV@" & RplChar(invoiceLine, "'", " ") & " " & RplChar(invoiceLine2, "'", " ") & " " & RplChar(invoiceLine3, "'", " ")
Print #2, strLine
xcount = xcount + 1
Loop
End If
Loop
Loop
MsgBox "Conversion Complete. Please upload the target file to Citidirect.", vbInformation + vbOKOnly
Close #1
Close #2
Exit Sub
ErrorTrap:
MsgBox "Error : " & Err.Description, vbCritical + vbOKOnly
Close #1
Close #2
End Sub
Here I attached a sample textfile that will be used to upload and convert it to another text file.
Bookmarks