Hi All,
I'm using Excel 2003.
My goal: Execute macro to save numerous spreadsheets to .tsv file format
My Problem: getting a fileformat to save in tsv format.
I can save a spreadsheet as a tsv manually. When I record the macro I see:
ActiveWorkbook.SaveAs Filename:= _
"C:\testing.tsv" _
, FileFormat:=xlText, CreateBackup:=False
When I run this in my macro I trap the error: Application-defined or object-defined error
Set newWks = ActiveSheet
With newWks
.SaveAs Filename:="C:\TSV\" & newWks.Name & ".tsv", FileFormat:=xltext,
End With
I can successfully create a csv using:
Set newWks = ActiveSheet
With newWks
.SaveAs Filename:="C:\TSV\" & newWks.Name & ".tsv", FileFormat:=6,
End With
What value of FileFormat will create a tsv? Or, is there another way?
Regards,
-Brian
Last edited by eBrian; 12-21-2010 at 05:41 PM.
The following macro will create a TSV file for a contiguous set of data starting in the top left of the sheet.
Sub CreateTSV() Open "C:\temp\MyTSVFile.tsv" For Output As #1 For N = 1 To Cells(1, 1).CurrentRegion.Rows.Count FileLine = "" For M = 1 To Cells(1, 1).CurrentRegion.Columns.Count FileLine = FileLine & Cells(N, M) & Chr$(9) Next M FileLine = Left(FileLine, Len(FileLine) - 1) Print #1, FileLine Next N Close #1 End Sub
Martin
Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.
If my solution has saved you time and/or money, please consider donating to Cancer Research UK.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks