Word macro to save files as .txt

J

Jack Burman

Would like to strip formatting from large group of small files and save as
text files.
Can a Word 2003 macro be created that will take a folder of small .docs and
save all .docs as .txt files. If so, how can this be done? If not, is there
some other method that can be used to automate this task.

Ultimately, would like to concatenate all .txt files into one large file and
use in another program - not word processing program.

Thanks
 
D

Doug Robbins - Word MVP

You could modify the macro in the article "Find & ReplaceAll on a batch of
documents in the same folder†at:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

by deleting all of the stuff about finding and replacing so that it just
opened each document and incorporating the following example from the Visual
Basic Help file so that it saved each document as a text file

Sub SaveAsTextFile()
Dim strDocName As String
Dim intPos As Integer

'Find position of extension in file name
strDocName = ActiveDocument.Name
intPos = InStrRev(strDocName, ".")

If intPos = 0 Then

'If the document has not yet been saved
'Ask the user to provide a file name
strDocName = InputBox("Please enter the name " & _
"of your document.")
Else

'Strip off extension and add ".txt" extension
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".txt"
End If

'Save file with new extension
ActiveDocument.SaveAs FileName:=strDocName, _
FileFormat:=wdFormatText
End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
J

Jack Burman

Thanks. This should do the trick!

Doug Robbins - Word MVP said:
You could modify the macro in the article "Find & ReplaceAll on a batch of
documents in the same folder†at:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

by deleting all of the stuff about finding and replacing so that it just
opened each document and incorporating the following example from the Visual
Basic Help file so that it saved each document as a text file

Sub SaveAsTextFile()
Dim strDocName As String
Dim intPos As Integer

'Find position of extension in file name
strDocName = ActiveDocument.Name
intPos = InStrRev(strDocName, ".")

If intPos = 0 Then

'If the document has not yet been saved
'Ask the user to provide a file name
strDocName = InputBox("Please enter the name " & _
"of your document.")
Else

'Strip off extension and add ".txt" extension
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".txt"
End If

'Save file with new extension
ActiveDocument.SaveAs FileName:=strDocName, _
FileFormat:=wdFormatText
End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.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