Automation: how to automate the conversion of .doc to .docx?

I have a group of .doc files in a folder that I need to convert to .docx.

To manually convert .doc to .docx is quite simple:

  • Open .doc in Word 2007
  • Click Save As ...
  • Save it as .docx

However, doing this for hundreds of files is definitely not fun. = P

How would you automate this?

+9
automation
source share
5 answers

Word Automation.

If you use .NET, add Microsoft.Office.Interop.Word (make sure it's version 12, equivalent to Word 2007 so you can achieve the above), in your project and use it to automate the Word application, do exactly what you want to do higher. Pseudo code

  • Create Application Object
  • Using an application object to open a document (by providing it with a file name)
  • Use the application object to execute SaveAs, providing it with the format and name of the output file
  • Close current document
  • Go through the above until you are done with all the documents.
  • Code for holding Word or Doc objects

You can find many examples on Google, just search for Word Automation in C # or something in that direction.

+4
source share

There is no need to automate Word, which is rather slow and fragile due to pop-up messages or using Microsoft Office File Converter (ofc.exe), which has an unnecessarily complicated user interface.

The easiest and fastest way is to install either Office 2007, or download and install the Microsoft compatibility package (if you haven’t already). Then you can easily convert from .doc to .docx using the following command:

"C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme <input file> <output file> 

where <input file> and <output file> must be fully qualified path names.

The command can be easily applied to multiple documents with for :

 for %F in (*.doc) do "C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme "%F" "%Fx" 
+18
source share

The easiest way is to use the Office File Converter command line. Just run

 ofc 

and magic happens.

+7
source share

WD2000: How to Use (OLE) Automation with Word . This is for Word 2000, but the model is still applied.

0
source share
0
source share

All Articles