F
Frank
Hi All,
I am using a script to convert an Excel sheet to a txt file and it works ok.
But some fields need to be aligned to the right in stead of default left. Can
anyone tell me how to do this? Not all values but only some of the fields in
the excel sheets
The code used:
Public Sub FixedFieldTextFile()
Const DELIMITER As String = ""
Const PAD As String = " "
Dim vFieldArray As Variant
Dim myRecord As Range
Dim nFileNum As Long
Dim i As Long
Dim sOut As String
vFieldArray = Array(4, 8, 4, 4, 15, 4, 13, 8, 8, 25, 40, 123)
nFileNum = FreeFile
Open "c:\NOB50850.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For i = 0 To UBound(vFieldArray)
sOut = sOut & DELIMITER & Left(.Offset(0, i).Text & _
String(vFieldArray(i), PAD), vFieldArray(i))
Next i
POLine = POLine + 1
Print #nFileNum, Mid(sOut, Len(DELIMITER) + 1)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub
The excel sheet:
Left Left Right Left
Right
5010 12345678 1 Custpart1 0 10
Left Left Left
01/07/07 19/06/07 G16SA3C
I am using a script to convert an Excel sheet to a txt file and it works ok.
But some fields need to be aligned to the right in stead of default left. Can
anyone tell me how to do this? Not all values but only some of the fields in
the excel sheets
The code used:
Public Sub FixedFieldTextFile()
Const DELIMITER As String = ""
Const PAD As String = " "
Dim vFieldArray As Variant
Dim myRecord As Range
Dim nFileNum As Long
Dim i As Long
Dim sOut As String
vFieldArray = Array(4, 8, 4, 4, 15, 4, 13, 8, 8, 25, 40, 123)
nFileNum = FreeFile
Open "c:\NOB50850.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For i = 0 To UBound(vFieldArray)
sOut = sOut & DELIMITER & Left(.Offset(0, i).Text & _
String(vFieldArray(i), PAD), vFieldArray(i))
Next i
POLine = POLine + 1
Print #nFileNum, Mid(sOut, Len(DELIMITER) + 1)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub
The excel sheet:
Left Left Right Left
Right
5010 12345678 1 Custpart1 0 10
Left Left Left
01/07/07 19/06/07 G16SA3C