使用宏将Excel文件保存为TSV

时间:2012-02-22 16:49:00

标签: excel excel-vba tsv vba

我想在我的Excel文件中创建一个特殊按钮,将文件自动保存为TSV

任何人都可以帮助我...这是一个指南或指向正确的方向。谢谢。

我非常感谢你的帮助。

谢谢!

2 个答案:

答案 0 :(得分:2)

这应该可行,并重新启用当前的实际工作簿

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

答案 1 :(得分:1)

这应该有用,只需更改路径

即可
Sub test()

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

End Sub