Can anyone fix one line of VBA code for Word to text conversion?

A

admin4office

The following VBA script opens Word documents in the directory C:\src, and
saves their contents as text files in the directory C:\dest. Unfortunately,
the saved text files include Word formatting, which crimps my plan to index
the contents with Perl. I would much rather that the files be saved as plain
text. The line that I think needs fixing is indicated with an arrow
(<----**). Does anyone have any ideas? Thanks much.


Sub SaveAllWord()
Dim srcPath As String
Dim destPath As String
Dim sName As String
Dim dt As Document
srcPath = "C:\src\"
destPath = "C:\dest\"
sName = Dir(srcPath & "*.doc")
Do
Set dt = Documents.Open(srcPath & sName)
dt.SaveAs
ActiveDocument.SaveAs destPath & dt.Name & ".txt", _
FileFormat = wdFormatText '<----**
ActiveDocument.Close SaveChanges:=False
sName = Dir()
Loop While sName <> ""
End Sub
 
J

Jonathan West

You've missed a colon. The vital line should be this

ActiveDocument.SaveAs FileName:=destPath & dt.Name & ".txt", _
FileFormat:= wdFormatText

When you are assigning values to the parameters passed in a mthod or
subroutine call, you need a color with the equals sign.

When you are assigning values to properties or variables, you don't.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
A

admin4office

Thanks very much! This will make my life a great deal easier.

admin4office_perl_programmer
 

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