How to get the Revision Number of a Word document using Python?

I need to get the revision number of a document in Word.

I've already got the version number but I have not found a way to get the revision number yet.

Upvotes: 0

Views: 277

Answers (1)

gpsgui
gpsgui

Reputation: 38

you can use the win32 api for python, that includes the COM module:

import win32com.client as win32

def getRevisionNumberWord(path):
    word = win32.gencache.EnsureDispatch('word.application')
    doc = word.Documents.Open(path, Visible = False)
    props = list(doc.BuiltInDocumentProperties)
    revNumber = int(props[7].value)     # the "Revision number" property is the index 7 of the properties list
    doc.Close()
    word.Quit()
    return revNumber

Upvotes: 1

Related Questions