Who Can Expand Chip Pearson's procedure ExportToTextFile?
Try the below. You need to adjust the endrow and end column to suit your
requirement OR you can set that to the last row, last col...
Sub OutputAsFixedWidthPipe()
Dim lngRow As Long
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
Dim intFile As Integer
Dim strData As String
intFile = FreeFile
lngLastRow = 20
lngLastCol = 10
Open "c:\test.txt" For Output As #intFile
For lngRow = 1 To lngLastRow
strData = ""
For lngCol = 1 To lngLastCol
strData = strData & "|" & Cells(lngRow, lngCol) & _
Space(10 - Len(Cells(lngRow, lngCol)))
Next lngCol
Print #intFile, Mid(strData, 2)
Next lngRow
Close #intFile
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria
"Curious" wrote:
I want to use his procedure "ExportToTextFile". But I need more. The
exported spreadsheet needs to be in text format to satisfy two
conditions: (1) pipe "|" delimiter and (2) fixed width, say each field
must be 10 character wide(including the delimiter).
My understanding is that we can create a text file either (not both)
with fixed width or with delimiter. How can I satisfy both?
Thanks in advance for any clue.
H.Z.
|