El TecnoBaúl de Kiquenet

Kiquenet boring stories

Archive for 20 febrero 2014

Convert DOC (Office 97-2003) to DOCX (Office 2010) programatically or Bulk

Posted by kiquenet en 20 febrero 2014

Option 1) OMPM – Using  Office File Converter (OFC) and Version Extraction Tool

Download Office Migration Planning Manager (OMPM) to the machine that hosts the files.

Office Migration Planning Manager (OMPM): Office Compatibility
The Office Migration Planning Manager (OMPM) 2010 is a group of tools designed to help administrators during the planning and testing phases of a Microsoft Office 2010 or Office 365 deployment.

The installer extracts all tools and resource files by default to C:\OMPM

If your machine does not have Office 2003 installed, which by now it probably does not, then you will also need to install the Office compatibility pack to convert the files.

Módulo de compatibilidad de Microsoft Office para formatos de archivos de Word, Excel y PowerPoint

Once that is installed, open the C:\OMPM\Tools folder that contains tools the Office File Converter (OFC) and Version Extraction Tool (VET)

Using OMPM tools
Use the Office File Converter (OFC) to do bulk conversions of specific Office files that are in version 97 through 2003 file formats to the Office 2010 file formats.


Edit OFC.INI file.

For the OFC.exe to work there must be a [FoldersToConvert] entry in the OFC.INI file.

Fldr=C:\OMPM\TOOLS\EXAMPLE FOLDER\ (in this case I put all the files I wanted to convert into the “EXAMPLE FOLDER”)

You can put multiple folders under this folder,

OFC.exe will follow this path a convert all DOC and XLS files into DOCX and XLSX files.

It will leave the old DOC file in the folder and create the new DOCX file right alongside.

The date created field will NOT change for the new DOCX or XLSX files

All the new files will be created in the appropriate folder, even if there are multiple layers of folders under the original location

In this case, the SourcePathTemplate and the DestinationPathTemplate listings in the OFC.INI file are just:



Option 2) PowerShell

Requires Office 2010 installed

The main:

$CompatMode = [Enum]::Parse([Microsoft.Office.Interop.Word.WdCompatibilityMode], "wdWord2010")
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat],"wdFormatDocumentDefault");

$word = new-object -comobject word.application
$word.Visible = $False

Get-ChildItem -path $folderpath -recurse -include $fileType | % {

    SaveDocumentWithCompatibilityMode $word $_
    ConvertDocument $word $_

#Clean up
$rc = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($word)
$word = $null

Save Document with Compatibility

Function SaveDocumentWithCompatibilityMode($word, $document)
    $opendoc = $word.documents.open($document.FullName)
    $savename = ($document.Fullname).substring(0,($document.FullName).lastindexOf("."))
    $savename = $savename + "_test1.docx"
    $opendoc.saveas([ref]"$savename", [ref]$saveFormat);
    $converteddoc = Get-ChildItem -Path $savename
    $opendoc = $word.documents.open($converteddoc.FullName)

I prefer Convert Document

Function ConvertDocument($word, $document)
    $opendoc = $word.documents.open($document.FullName)
    #$opendoc = $word.documents.open($document.FullName,$false,$true);
    $savename = ($document.fullname).substring(0,($document.FullName).lastindexOf("."))
    $savename = $savename + "_test2.docx"
    $opendoc.saveas([ref]"$savename", [ref]$saveFormat);
    # Stop Winword Process
    #$rc = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($opendoc)








Posted in Herramientas, Productividad, Scripts | Etiquetado: , , , , | Leave a Comment »