Macro for Microsoft Excel to Export Pipe Delimited Data
This was originally posted to our forum by one of our users.
here is the macro for Excel that will export to a pipe delimetd file,
called data.txt, stored in C:
------------------------ Macro Below this line -----------------------
Sub ExportDB()
' This macro saves the active worksheet to a pipe-delimited flat file at c:data.txt
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim DataTextStr As String
ListSep = "|"
Set SrcRg = ActiveSheet.UsedRange
Open "C:data.txt" For Output As #1
For Each CurrRow In SrcRg.Rows
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrTextStr = CurrTextStr & CurrCell.Value & ListSep
Next
While Right(CurrTextStr, 1) = ListSep
CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) - 1)
Wend
'Added next line to put | at end of each line
CurrTextStr = CurrTextStr & ListSep
Print #1, CurrTextStr
Next
Close #1
End Sub
|