Text File Formating?
Text File Formating?
(OP)
I just posted this question on the MS VB forum.
how could this be done through VBA in Excel? Or, can it be done?
"I am very new to VB and, am trying my hand at VB6.
I think!, I know how to creat a text file and have a string written to it.
What I am trying to do is have a column header, say, starting at column 15 of the second line and have the header field limitted to 10 spaces. have another header at column 30 .....etc. and have the coresponding values written below each header.
I will appreciate a sample code or name of a reference where to look this up."
Thank you
how could this be done through VBA in Excel? Or, can it be done?
"I am very new to VB and, am trying my hand at VB6.
I think!, I know how to creat a text file and have a string written to it.
What I am trying to do is have a column header, say, starting at column 15 of the second line and have the header field limitted to 10 spaces. have another header at column 30 .....etc. and have the coresponding values written below each header.
I will appreciate a sample code or name of a reference where to look this up."
Thank you





RE: Text File Formating?
SA
RE: Text File Formating?
this is a rude example. The idea is to build a line of data and print to file.
HTH
LF
CODE
Dim Ztring As String, sLine As String
Dim n1 As String, n2 As String, n3 As String, n4 As String
Ztring = Space(80) ' page width 80 chars
Open "C:\TextFile.txt" For Output As 1
Print #1, vbCr ' blank line
sLine = InsertAt("Title_Line @ Col34", 34, Ztring) ' title
sLine = InsertAt(Date, 80 - Len(Date), sLine)
Print #1, sLine: Print #1, vbCr
sLine = InsertAt("C01 @ Col8", 8, Ztring) ' column headers
sLine = InsertAt("C02 @ Col22", 22, sLine)
sLine = InsertAt("C03 @ Col44", 44, sLine)
sLine = InsertAt("C04 @ Col65", 65, sLine)
Print #1, sLine: Print #1, vbCr
For i% = 1 To 50 ' say writing 50 lines...
n1 = "Line #" & Format(i%, "00")
n2 = Format(((500 * Rnd) + 0.001), "000.00000")
n3 = Format(((50 * Rnd) + 0.001), "00.00000")
n4 = Format(((5 * Rnd) + 0.001), "#.0000000")
sLine = InsertAt(n1, 17 - Len(n1), Ztring)
sLine = InsertAt(n2, 32 - Len(n2), sLine)
sLine = InsertAt(n3, 54 - Len(n3), sLine)
sLine = InsertAt(n4, 75 - Len(n4), sLine)
Print #1, sLine ' line of data...
Next
Close 1
End Sub
Public Function InsertAt(What As String, At As Integer, Where As String)
Dim l2 As String, l3 As String
l0 = Len(Where)
l1 = Len(What)
l2 = Left(Where, At - 1)
l3 = Right(Where, l0 - (l1 + At) + 1)
InsertAt = l2 & What & l3
End Function