Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Read File Write File Code Question

Status
Not open for further replies.
Jun 25, 2002
8
US
How do you Read a file in and Write a file out in a Comma Delimited format. I realize this is probably basic stuff but I am really new to VBA.

Example I have a (file named F30001x30.txt) and I want to produced the comma delimited format into a (file named F30001q30.txt)

Any help would be greatly appreciated.

Jason Neuman
 
Just record yourself opening the file into excel and then saving it as .csv
HTH
Geoff
 
Via Excel:

ChDir "C:\"
Workbooks.OpenText FileName:="C:\F30001x30.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1))
ActiveWorkbook.SaveAs FileName:="C:\F30001q30.csv", FileFormat:=xlCSV, _
CreateBackup:=False
 
Just a note to say that this will work for the main part but the
FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1))
line will change dependant on number of fields - that's the problem with opening .txt files, the array is different every time which is why you need to record it on the text file you will be using
HTH
Geoff
 
How do you Read a file in and Write a file out in a Comma Delimited format. I realize this is probably basic stuff but I am really new to VB.

Example I have a (file named F30001x30.txt) and I want to produced the comma delimited format into a (file named F30001q30.txt)

Any help would be greatly appreciated.


I realize I asked for VBA on the other post but I meant to put VB. Thank you for the previous help
 
Maybe you should post this question in the VB forum then
Do a serarch on forums for "VB" and about 6 or 7 come up - would've thought they'd know in there
HTH
Geoff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top