Fundamentals 4 min read

Batch Convert .doc to .docx Using Python and win32com

This guide explains how to handle mixed .doc and .docx files by installing the win32com library, providing step‑by‑step code to batch convert .doc documents to .docx format and then process them with python‑docx for automated office workflows.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Batch Convert .doc to .docx Using Python and win32com

Problem Introduction

In daily work we often need to process large numbers of Excel and Word files. When faced with mixed .xls/.xlsx/.xlsm or .doc/.docx files, using VBA is possible but Python offers a much simpler batch solution.

This article focuses on converting .doc files to .docx so they can be processed with python-docx, which only supports the newer format.

Installing win32com

If pip install win32com fails, use the alternative command:

python -m pip install pypiwin32

win32com Syntax Overview

The following snippet shows how to launch Word via COM, run it in the background, and suppress alerts:

# Call Word application
WordApp = win32com.client.Dispatch("Word.Application")

# Run in background, no UI, no alerts
WordApp.Visible = 0
WordApp.DisplayAlerts = 0

Full Conversion Script (Procedural Style)

import os
import time
import win32com
from win32com.client import Dispatch

def doc_to_docx(path):
    w = win32com.client.Dispatch('Word.Application')
    w.Visible = 0
    w.DisplayAlerts = 0
    doc = w.Documents.Open(path)
    # Absolute path required
    newpath = allpath + '\\ConvertedDocument.docx'
    time.sleep(3)  # pause to avoid error -2147352567
    doc.SaveAs(newpath, 12, False, "", True, "", False, False, False, False, False)
    # doc.Close()  # Uncomment to delete original .doc
    w.Quit()  # exit Word
    return newpath

allpath = os.getcwd()
print(allpath)
# Example usage
doc_to_docx(allpath + '\\OriginalDocument.doc')

Result

The script converts each .doc file in the specified directory to a .docx file, ready for further automated processing.

Conversion result
Conversion result
docxOfficewin32combatch-processing
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.