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
--
admin4office_perl_programmer.

Re: Can anyone fix one line of VBA code for Word to text conversion? by Jonathan

Jonathan
Fri Mar 11 15:01:23 CST 2005

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

"admin4office" <admin4office@discussions.microsoft.com> wrote in message
news:6477DD92-CF23-4037-96B5-1455332C5132@microsoft.com...
> 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
> --
> admin4office_perl_programmer.


Re: Can anyone fix one line of VBA code for Word to text conversio by admin4office

admin4office
Sat Mar 12 22:09:02 CST 2005

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

admin4office_perl_programmer

"Jonathan West" wrote:

> 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
>
> "admin4office" <admin4office@discussions.microsoft.com> wrote in message
> news:6477DD92-CF23-4037-96B5-1455332C5132@microsoft.com...
> > 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
> > --
> > admin4office_perl_programmer.
>
>