How to batch convert Word documents to txt file?
This article is talking about how to batch convert all Word documents in a specific folder to separate TXT files in Word.
The below VBA code can help to convert all Word documents in a specific folder to txt files at once. Please do as follows.
1. In Word document, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below code into the Module window.
VBA code: Batch convert Word documents to txt files
Sub ConvertDocumentsToTxt() 'Updated by Extendoffice 20181123 Dim xIndex As Long Dim xFolder As Variant Dim xFileStr As String Dim xFilePath As String Dim xDlg As FileDialog Dim xActPath As String Dim xDoc As Document Application.ScreenUpdating = False Set xDlg = Application.FileDialog(msoFileDialogFolderPicker) If xDlg.Show <> -1 Then Exit Sub xFolder = xDlg.SelectedItems(1) xFileStr = Dir(xFolder & "\*.doc") xActPath = ActiveDocument.Path While xFileStr <> "" xFilePath = xFolder & "\" & xFileStr If xFilePath <> xActPath Then Set xDoc = Documents.Open(xFilePath, AddToRecentFiles:=False, Visible:=False) xIndex = InStrRev(xFilePath, ".") Debug.Print Left(xFilePath, xIndex - 1) & ".txt" xDoc.SaveAs Left(xFilePath, xIndex - 1) & ".txt", FileFormat:=wdFormatText, AddToRecentFiles:=False xDoc.Close True End If xFileStr = Dir() Wend Application.ScreenUpdating = True End Sub
3. Press the F5 key to run the code.
4. In the Browse window, select the folder contains Word documents you will convert to txt files, and click the OK button. See screenshot:
Then you can see all documents in selected folder are converted to txt files at once. See screenshot:
Recommended Productivity Tools
- Complicated and repeated operations can be done a one-time processing in seconds.
- Insert multiple images across folders into Word document at once.
- Merge and combine multiple Word files across folders in to one with your desired order.
- Split the current document into separate documents according to heading 1, section break or other criteria.
- Convert files between Doc and Docx, Docx and PDF, collection of tools for common conversions and selection, and so on...