How can i batch convert a bunch of DOCX and DOC files into plain t

K

KC

Hi there, I would like to convert a bunch of DOCX and DOC files to text
format form the command line. Does MS Office have any such batch conversion
tools? If not, what are my options?

Thanks,
- KC.
 
G

Graham Mayor

You cannot do it from the command line without the aid of some third party
converter that can handle both formats, but you can from a Word macro. I
posted a version of the following yesterday for another user who wanted to
save a batch as HTML. This version will save as Windows Text format. There
are however other text formats, which may be better suited to your
requirements.

wdFormatDOSText Microsoft DOS text format.
wdFormatDOSTextLineBreaks Microsoft DOS text with line breaks preserved.
wdFormatEncodedText Encoded text format.
wdFormatText Microsoft Windows text format.
wdFormatTextLineBreaks Windows text format with line breaks
preserved.
wdFormatUnicodeText Unicode text format.

Replace as necessary for FileFormat:=wdFormatText
http://www.gmayor.com/installing_macro.htm

Sub SaveAllAsTXT()
Dim strFileName As String
Dim strDocName() As String
Dim strPath As String
Dim oDoc As Document
Dim Response As Long
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "Save all as Text"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFileName = Dir$(strPath & "*.doc")
While Len(strFileName) <> 0
Set oDoc = Documents.Open(strPath & strFileName)
strDocName = Split(ActiveDocument.FullName, ".")
If ActiveDocument.SaveFormat = 0 Or _
ActiveDocument.SaveFormat = 12 Then
ActiveDocument.SaveAs _
FileName:=strDocName(0) & ".txt", _
FileFormat:=wdFormatText
End If
oDoc.Close SaveChanges:=wdDoNotSaveChanges
strFileName = Dir$()
Wend
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top