How to Automatically Save an Excel Worksheet as a TSV File with VBA
Question details
The user wants to export an Excel worksheet automatically as a tab-separated file (.tsv) with a preset filename using VBA, completely bypassing manual Save As prompts.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating the export of spreadsheet data into a structured text format (TSV) for downstream system integration or data processing.
- Observed behavior
- By default, Excel requires manual interaction to specify a filename, format, and confirm overwrites. The goal is to make this process silent and automatic upon saving.
Ensure the Developer tab is enabled in your ribbon to access the VBA editor. Verify that your desired destination folder path is accessible and that you have permission to write files there.
Automate TSV Export Using the Workbook_AfterSave Event
Trigger a custom VBA macro to export the current worksheet to a TSV file automatically every time the workbook is saved.
A TSV (Tab-Separated Values) file is a standard tab-delimited text file. By tying a VBA export script to the Workbook_AfterSave event, you can force the application to automatically generate the TSV file in the background without prompting for a filename or format.
Press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, locate your current workbook and double-click on 'ThisWorkbook'.
From the left dropdown menu above the code window, select 'Workbook'. Then, from the right dropdown menu, select 'AfterSave'.
Inside the event subroutine, insert a script to save the active sheet. Use the SaveAs method with FileFormat:=xlText (which denotes tab-delimited text) and a preset Filename (e.g., "C:\Path\Testing_1.tsv").
Wrap your SaveAs command with Application.DisplayAlerts = False before the save operation, and Application.DisplayAlerts = True immediately after it to ensure Excel overwrites the existing file without asking.

Automate Worksheets and Macros Seamlessly with WPS Spreadsheet
WPS Spreadsheet offers robust support for VBA macros, allowing you to easily automate tasks like exporting data to TSV or CSV formats. It provides a familiar developer interface for writing, editing, and executing your automation scripts seamlessly.
- 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and open your workbook in WPS Spreadsheet.
- 2. Open the Developer Tools: Navigate to the 'Tools' tab on the ribbon and click on 'Developer' to access the built-in VBA Editor.
- 3. Insert Your VBA Script: Paste your automatic TSV export macro into the 'ThisWorkbook' module.
- 4. Save as a Macro-Enabled File: Save your document as an .xlsm (Macro-Enabled Workbook) to ensure your automation scripts are preserved and ready to execute.

Frequently Asked Questions
How do I stop the macro from asking to overwrite an existing TSV file?
Add the line 'Application.DisplayAlerts = False' right before your SaveAs command in the VBA code. Be sure to turn alerts back on by adding 'Application.DisplayAlerts = True' after the save command executes.
What is the correct FileFormat constant for TSV in Excel VBA?
To save a file as tab-separated values (TSV), you should use 'FileFormat:=xlText' (which represents the numeric value 20) or 'xlTextWindows'.
Can I export only a specific range of cells instead of the entire worksheet?
Yes. Instead of using the Worksheet.SaveAs method, you can write a custom VBA subroutine that reads a specific 'Range' and writes the cell values directly to a text file with tab characters (Chr(9)) using standard file I/O operations.




