How to determine the document type with the ActiveDocument object in Word?


is there any way to determine the document type of a Word document with the ActiveDocument object?

I am not referring to the difference between template and document which can be determined via the ActiveDocument.Type property. Rather I need to know if the active document is a Word97 document or a Word 2007/2010 document (typical extension is "docx").
(To do this via extension is not secure because the new XML type can also be saved with the old extension, of course.)
I have found no property of the ActiveDocument object that suits my need. Have I overlooked a property? If not, is there a reliable indirect way to determine the doc type, maybe via some properties that are only available for XML documents?

Any help is highly appreciated.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:

You could try this:

Dim ADName As String

ADName = LCase(ActiveDocument.Name)

If ADName Like "*.do[ct]" Or ADName Like "*.do[ct][mx]" Then
    Select Case Mid(ADName, InStrRev(ADName, ".") + 1)
        Case "doc": MsgBox "Word 97-2003 document"
        Case "dot": MsgBox "Word 97-2003 templte"
        Case "docx": MsgBox "Word 2007-2010 document"
        Case "docm": MsgBox "Word 2007-2010 template"
    End Select
    MsgBox "Cannot determine file type; ActiveDocument not saved yet"
End If

Open in new window

hcbrunsAuthor Commented:
Hello Matthew,

thanks for your suggestion, but, unfortunately, this does not solve my problem. For, as I have already stated in my original question, to just check the extension is not reliable because a Word document can be saved with any extension. A Word 2007 format document can also be saved with the "doc" extension.

I was rather asking for a reliable way to check the document type via the Document object. Is there any way to do this?

Patrick MatthewsCommented:
I see.

The SaveFormat property looks promising.  It returns one of the WdSaveFormat constants; you can check the values for those in the Object Explorer.

For example, a Word 2003 document (doc) is 0 (wdFormatDocument), and a Word 2007 macro-enabled template (dotm) is 15 (wdFormatXMLTemplateMacroEnabled).


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hcbrunsAuthor Commented:
Thanks, Patrick!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.