Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
 
Posts: n/a
Default Need help with creating a text file via excel

I'm trying to create a text file that will keep the fields a constant
length, although the data within them varies length.

The following VB almost does what I want EXCEPT that the padding in
fields 4 to 31 (set at 6 characters) is trailing the actual data and I
want it to be leading (eg field 4 may be 693, but it comes out as
693000).

if the 3 trailing zero's were at the front, then the application I'm
sending it to (AS400) would strip them leaving just the 693.

Const DELIMITER As String = "" 'Normally none
Const PAD As String = " " 'or other character
Dim vFieldArray As Variant
Dim myRecord As Range
Dim nFileNum As Long
Dim i As Long
Dim sOut As String

'vFieldArray contains field lengths, in characters, from field
1 to N
vFieldArray = Array(11, 4, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6)
nFileNum = FreeFile
Open "C:\planning\MPS.TXT" For Output As #nFileNum
For Each myRecord In Range("C7:C" & Range("C" &
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
Print #nFileNum, Mid(sOut, Len(DELIMITER) + 1)
sOut = Empty

End With

Next myRecord
Close #nFileNum
End Sub


Any help is appreciated

  #2   Report Post  
JE McGimpsey
 
Posts: n/a
Default

One way:

sOut = sOut & DELIMITER & Right(String(vFieldArray(i), PAD) & _
.Offset(0, i), vFieldArray(i))


Left(.Offset(0, i).Text &
String(vFieldArray(i), PAD), vFieldArray(i))
In article .com,
wrote:

sOut = sOut & DELIMITER & Left(.Offset(0, i).Text &
String(vFieldArray(i), PAD), vFieldArray(i))

  #3   Report Post  
 
Posts: n/a
Default

Thanks for your quick reply

  #4   Report Post  
 
Posts: n/a
Default

That works, Much appreciated.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I convert an excel file to a flat text file Lannutslp Excel Discussion (Misc queries) 1 June 3rd 05 10:17 AM
Convert excel file to flat text file Gary's Student Excel Discussion (Misc queries) 0 June 1st 05 12:17 AM
Excel File in Use Notification Missing?? JoD317 Excel Discussion (Misc queries) 6 April 19th 05 02:33 PM
Locating a file in excel with a partial file name. Audra Excel Discussion (Misc queries) 1 February 19th 05 08:51 PM
Locating a file in excel with a partial file name. Audra Excel Discussion (Misc queries) 0 February 19th 05 02:01 PM


All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"