November 12, 2019

Convert Each Worksheet in Workbook to Text File

How to convert each worksheet in workbook to text file automatically with Excel VBA.
Here’s the complete VBA code:

Option Explicit

Sub saveSheetsAsTextFiles()

Dim wksht As Worksheet

Application.DisplayAlerts = False

For Each wksht In ActiveWorkbook.Worksheets

ActiveWorkbook.SaveAs Filename:=”C:\ExcelToText\” & wksht.Name & “.txt”, FileFormat:=xlText

Next wksht

Application.DisplayAlerts = True

End Sub