Home » excel » Saving Excel Files as TSV using Macro

Saving Excel Files as TSV using Macro

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’d like to create a special button in my excel file that saves the file as TSV automatically

can anyone help me with this.. a guide or point me to the right direction. Thank you.

I’d really appreciate your help.

Thank you!

How to&Answers:

This should work, just change the path

Sub test()

    ActiveWorkbook.SaveAs Filename:="C:\Users\User\Desktop\Book1.tsv", _
        FileFormat:=xlText, CreateBackup:=False

End Sub

Answer:

This should work, and re-Enable the current real workbook

Sub tsv()
 ' save the current fileName for re-save later
    BookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name
    ' select the good Sheet.Range
    Sheets("TSV-Sheet").Range("A1:N25").Select
    ' dont display alert when already exist
    Application.DisplayAlerts = False

    ' save TSV file
    ActiveWorkbook.SaveAs Filename:="C:\Users\User\Desktop\Book1.tsv", FileFormat:=xlText, CreateBackup:=False

    ' change the sheetName modified by previous SaveAs
    ActiveSheet.Name = "TSV-Sheet"

    ' Resave the real WorkBook (because the current workbook is *.TSV)
    ActiveWorkbook.SaveAs Filename:=BookName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    Application.DisplayAlerts = True
End Sub