+ Reply to Thread
Results 1 to 2 of 2

Thread: What fileformat to save as tsv

  1. #1
    Registered User
    Join Date
    12-21-2010
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    1

    What fileformat to save as tsv

    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.

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004

    Re: What fileformat to save as tsv

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0