Code to convert many *.doc files to *.txt

R

Rob

Hi,

I have over 500 Word doc files I need to convert to text format so that I
can import them to a database program. I plan to open 20 or so files at a
time and I would like a macro to save each file by the same name as the
original, but with the txt extension, overiding any warning message/s that
format will be lost, etc.

I'm guessing I need to do this in Word, but if there's a better solution to
do this than I'm open to any suggestions. (If anyone knows how to create
something whereby I can import the files to the program called ZionWorx,
which is a song display program using multimedia such as a data projector,
I'd love to hear from you too!)

Rob
 
J

Jezebel

Rob said:
Hi,

I have over 500 Word doc files I need to convert to text format so that I
can import them to a database program. I plan to open 20 or so files at
a time and I would like a macro to save each file by the same name as the
original, but with the txt extension, overiding any warning message/s that
format will be lost, etc.

I'm guessing I need to do this in Word, but if there's a better solution
to do this than I'm open to any suggestions. (If anyone knows how to
create something whereby I can import the files to the program called
ZionWorx, which is a song display program using multimedia such as a data
projector, I'd love to hear from you too!)

Rob
 
J

Jezebel

If all the files are in the same folder --

Dim pOldFile As String
Dim pNewFile As String
Dim pDoc As Word.Document

Const pFolder As String = "..[folder]\"

Application.DisplayAlerts = wdAlertsNone
pOldFile = Dir(pFolder & "*.doc")
Do Until Len(pOldFile) = 0
Set pDoc = Documents.Open(FileName:=pFolder & pOldFile)
pNewFile = Left(pDoc.FullName, Len(pDoc.FullName) - 3) & "txt"
pDoc.SaveAs FileName:=pNewFile, fileformat:=wdFormatText
pDoc.Close savechanges:=False
pOldFile = Dir()
Loop
Application.DisplayAlerts = wdAlertsMessageBox
 
J

Jonathan West

Hi Rob,

If you did a full install of Office, you should have the Batch Conversion
Wizard awailable to you. This does exactly what you are trying to achieve.
 
R

Rob

Thanks Jezebel, but Jonathon's solution to use the Batch convertor seems an
easy solution.
I did try to run the code you submitted, but I'm a bit of a novice and I
think I probably needed to do some more work with that.....like put the path
and name to the folder, etc., somewhere in that code??

Rob

Jezebel said:
If all the files are in the same folder --

Dim pOldFile As String
Dim pNewFile As String
Dim pDoc As Word.Document

Const pFolder As String = "..[folder]\"

Application.DisplayAlerts = wdAlertsNone
pOldFile = Dir(pFolder & "*.doc")
Do Until Len(pOldFile) = 0
Set pDoc = Documents.Open(FileName:=pFolder & pOldFile)
pNewFile = Left(pDoc.FullName, Len(pDoc.FullName) - 3) & "txt"
pDoc.SaveAs FileName:=pNewFile, fileformat:=wdFormatText
pDoc.Close savechanges:=False
pOldFile = Dir()
Loop
Application.DisplayAlerts = wdAlertsMessageBox




Rob said:
Hi,

I have over 500 Word doc files I need to convert to text format so that I
can import them to a database program. I plan to open 20 or so files at
a time and I would like a macro to save each file by the same name as the
original, but with the txt extension, overiding any warning message/s
that format will be lost, etc.

I'm guessing I need to do this in Word, but if there's a better solution
to do this than I'm open to any suggestions. (If anyone knows how to
create something whereby I can import the files to the program called
ZionWorx, which is a song display program using multimedia such as a data
projector, I'd love to hear from you too!)

Rob
 
J

Jezebel

Well yes: put the folder name in this line

Const pFolder As String = "..[folder]\"



Rob said:
Thanks Jezebel, but Jonathon's solution to use the Batch convertor seems
an easy solution.
I did try to run the code you submitted, but I'm a bit of a novice and I
think I probably needed to do some more work with that.....like put the
path and name to the folder, etc., somewhere in that code??

Rob

Jezebel said:
If all the files are in the same folder --

Dim pOldFile As String
Dim pNewFile As String
Dim pDoc As Word.Document

Const pFolder As String = "..[folder]\"

Application.DisplayAlerts = wdAlertsNone
pOldFile = Dir(pFolder & "*.doc")
Do Until Len(pOldFile) = 0
Set pDoc = Documents.Open(FileName:=pFolder & pOldFile)
pNewFile = Left(pDoc.FullName, Len(pDoc.FullName) - 3) & "txt"
pDoc.SaveAs FileName:=pNewFile, fileformat:=wdFormatText
pDoc.Close savechanges:=False
pOldFile = Dir()
Loop
Application.DisplayAlerts = wdAlertsMessageBox




Rob said:
Hi,

I have over 500 Word doc files I need to convert to text format so that
I can import them to a database program. I plan to open 20 or so files
at a time and I would like a macro to save each file by the same name as
the original, but with the txt extension, overiding any warning
message/s that format will be lost, etc.

I'm guessing I need to do this in Word, but if there's a better solution
to do this than I'm open to any suggestions. (If anyone knows how to
create something whereby I can import the files to the program called
ZionWorx, which is a song display program using multimedia such as a
data projector, I'd love to hear from you too!)

Rob
 

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