Hello all,

I'm trying to adapt a script given here

http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/
hey0401.mspx

to do a massive conversion from word to TeX using the file converter
word2tex

http://www.chikrii.com/products/word2tex/dl/

What I've done is the fellowing:

'Begin script
Const wdFormatDocument = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='X:\annales'} Where " _
& "ResultClass = CIM_DataFile")

Set objWord = CreateObject("Word.Application")

Dim cnvTeX As FileConverter

For Each objFile in colFiles
If objFile.Extension = "doc" Then
strFile = "X:\annales\" & objFile.FileName & "." &
objFile.Extension
strNewFile = "X:\annales-TeX\" & objFile.FileName & ".tex"
Set objDoc = objWord.Documents.Open(strFile)
For Each cnvTeX In Application.FileConverters
If cnvTeX.ClassName = "TeX32exp" Then
objDoc.SaveAs strNewFile, _
FileFormat:=cnvTeX.SaveFormat
End If
Next cnvTeX
objDoc.Close
End If
Next

objWord.Quit
'End Script

where X:\annales is the directory where the .doc files are stored and X:
\annales-TeX is the diretory where I want the files converted to be
stored. TeX32exp is the ClassName for the FileConverter word2tex.

And guess what?... It does not work :-( I'm sorry but I'm not a vbs guru,
so if anyone could help, I would highly appreciate.

Thanks in advance

--
Christophe

Re: Convert 1,000 word documents to TeX by Pegasus

Pegasus
Fri Jul 11 05:17:09 CDT 2008


"Christophe Jorssen" <christophe.jorssen@libre.fr.invalid> wrote in message
news:48771c9c$0$19113$426a34cc@news.free.fr...
> Hello all,
>
> I'm trying to adapt a script given here
>
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/
> hey0401.mspx
>
> to do a massive conversion from word to TeX using the file converter
> word2tex
>
> http://www.chikrii.com/products/word2tex/dl/
>
> What I've done is the fellowing:
>
> 'Begin script
> Const wdFormatDocument = 0
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>
> Set colFiles = objWMIService.ExecQuery _
> ("ASSOCIATORS OF {Win32_Directory.Name='X:\annales'} Where " _
> & "ResultClass = CIM_DataFile")
>
> Set objWord = CreateObject("Word.Application")
>
> Dim cnvTeX As FileConverter
>
> For Each objFile in colFiles
> If objFile.Extension = "doc" Then
> strFile = "X:\annales\" & objFile.FileName & "." &
> objFile.Extension
> strNewFile = "X:\annales-TeX\" & objFile.FileName & ".tex"
> Set objDoc = objWord.Documents.Open(strFile)
> For Each cnvTeX In Application.FileConverters
> If cnvTeX.ClassName = "TeX32exp" Then
> objDoc.SaveAs strNewFile, _
> FileFormat:=cnvTeX.SaveFormat
> End If
> Next cnvTeX
> objDoc.Close
> End If
> Next
>
> objWord.Quit
> 'End Script
>
> where X:\annales is the directory where the .doc files are stored and X:
> \annales-TeX is the diretory where I want the files converted to be
> stored. TeX32exp is the ClassName for the FileConverter word2tex.
>
> And guess what?... It does not work :-( I'm sorry but I'm not a vbs guru,
> so if anyone could help, I would highly appreciate.
>
> Thanks in advance
>
> --
> Christophe

Since you need to convert a large number of documents, a batch
conversion approach would seem the obvious choice:
@echo off
cd /d "d:\My Word Files"
for %%a in (*.doc) do for %%b in ("%%a") do echo w2tcmdline "%%~nb%%~xb"
"%%~nb.TeX"

Watch out for line wrap. The last line starts with "for" and ends on 'TeX"'.
You need to determine the exact syntax for w2tcmdline.exe. Remove the
word "echo" in the last line to activate the batch file.