txt tab-delimited to CSV

  • Thread starter Thread starter kanaiona
  • Start date Start date
K

kanaiona

We use a program which is only able to export data into 'tab-
delimited' text files. We need data from this program to go to
another which can only read CSV files.

Is there a way to script this so it automatically converts the
contents of a text file to a csv which can be opened in excel?

Thanks
 
Hi,
XL is also able to open tab delimited files, but you have to open them via
XL.
What file format do you want to convert ?
Regards
JY
 
Hi,
XL is also able to open tab delimited files, but you have to open them via
XL.
What file format do you want to convert ?
Regards









- Show quoted text -

Thanks for replying.

Yes, i am aware XL can open tab-delimited but we need the process
automated so no user intervention is required.
 
ok, But what is the file format, eg .txt ?
JY
Thanks for replying.

Yes, i am aware XL can open tab-delimited but we need the process
automated so no user intervention is required.
 
ok, But what is the file format, eg .txt ?







- Show quoted text -

sorry, the tab-delimited is in text (txt) format.. and it is required
to be in CSV format.
:)
 
We use a program which is only able to export data into 'tab-
delimited' text files. We need data from this program to go to
another which can only read CSV files.

Is there a way to script this so it automatically converts the
contents of a text file to a csv which can be opened in excel?

Thanks

I got the answer on another topic now.

Thanks anyways
 
Maybe something like this:

Option Explicit
Sub testme01()

Dim myFileNames As Variant
Dim myArray() As Variant
Dim iCtr As Long
Dim maxFields As Long
Dim wkbk As Workbook
Dim NewFileName As String

maxFields = Worksheets(1).Columns.Count

myFileNames = Application.GetOpenFilename _
(filefilter:="Text Files, *.txt", MultiSelect:=True)

If IsArray(myFileNames) = False Then
Exit Sub 'user hit cancel
End If

ReDim myArray(1 To maxFields, 1 To 2)
For iCtr = 1 To maxFields
myArray(iCtr, 1) = iCtr
'bring it in as text--so nothing changes
myArray(iCtr, 2) = xlTextFormat
Next iCtr

For iCtr = LBound(myFileNames) To UBound(myFileNames)
Workbooks.OpenText Filename:=myFileNames(iCtr), _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, _
FieldInfo:=myArray

If LCase(Right(myFileNames(iCtr), 4)) = ".txt" Then
NewFileName = Left(myFileNames(iCtr), Len(myFileNames(iCtr)) - 4)
End If
NewFileName = NewFileName & ".csv"

Set wkbk = ActiveWorkbook

'overwrite any existing .csv file
Application.DisplayAlerts = False
wkbk.SaveAs Filename:=NewFileName, FileFormat:=xlCSV
Application.DisplayAlerts = True

wkbk.Close savechanges:=False

Next iCtr

End Sub
 
Back
Top