Hi All,
I have a macro that exports data in a | delimited format. All is working well except I can't get the macro to finish with a trailing pipe.
IE field1|field2|field3|
I have even put the final pipe in the last field, it still drops it. Does anyone have a pointer to a solution. I can't change the operating system delimiter as several things rely on comma delimiters.
Below is the code im using.
Thanks for any ideas.
Sub ExportPipeDelimited()
Dim vFF As Long, vSaveName As String
Dim i As Long, j As Long, l As Long
Dim CLLs() As String, Rws, vTempStr As String
'Get Exported File Name
vSaveName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:= _
"Pipe-delimited text,*.txt,All Files,*.*", Title:="Export Pipe Delimited ...")
If LCase(vSaveName) = "false" Then Exit Sub 'hit cancel
'Create array with pipe-delimited sheet data
Rws = ActiveSheet.UsedRange
ReDim CLLs(UBound(Rws, 1) - LBound(Rws, 1))
For i = LBound(Rws, 1) To UBound(Rws, 1)
vTempStr = ""
For j = LBound(Rws, 2) To UBound(Rws, 2)
vTempStr = vTempStr & "|" & Rws(i, j)
Next j
For l = Len(vTempStr) To 2 Step -1
If Mid$(vTempStr, l, 1) <> "|" Then Exit For
Next
CLLs(i - LBound(Rws, 1)) = Mid$(vTempStr, 2, l - 1)
Next i
'Transfer array contents to text file
vFF = FreeFile
Open vSaveName For Output As #vFF
For i = 0 To UBound(CLLs) - 1
Print #vFF, CLLs(i)
Next i
Print #vFF, CLLs(UBound(CLLs))
Close #vFF
End Sub
I have a macro that exports data in a | delimited format. All is working well except I can't get the macro to finish with a trailing pipe.
IE field1|field2|field3|
I have even put the final pipe in the last field, it still drops it. Does anyone have a pointer to a solution. I can't change the operating system delimiter as several things rely on comma delimiters.
Below is the code im using.
Thanks for any ideas.
Sub ExportPipeDelimited()
Dim vFF As Long, vSaveName As String
Dim i As Long, j As Long, l As Long
Dim CLLs() As String, Rws, vTempStr As String
'Get Exported File Name
vSaveName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:= _
"Pipe-delimited text,*.txt,All Files,*.*", Title:="Export Pipe Delimited ...")
If LCase(vSaveName) = "false" Then Exit Sub 'hit cancel
'Create array with pipe-delimited sheet data
Rws = ActiveSheet.UsedRange
ReDim CLLs(UBound(Rws, 1) - LBound(Rws, 1))
For i = LBound(Rws, 1) To UBound(Rws, 1)
vTempStr = ""
For j = LBound(Rws, 2) To UBound(Rws, 2)
vTempStr = vTempStr & "|" & Rws(i, j)
Next j
For l = Len(vTempStr) To 2 Step -1
If Mid$(vTempStr, l, 1) <> "|" Then Exit For
Next
CLLs(i - LBound(Rws, 1)) = Mid$(vTempStr, 2, l - 1)
Next i
'Transfer array contents to text file
vFF = FreeFile
Open vSaveName For Output As #vFF
For i = 0 To UBound(CLLs) - 1
Print #vFF, CLLs(i)
Next i
Print #vFF, CLLs(UBound(CLLs))
Close #vFF
End Sub