• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

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

Hi,

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.

Hermann
0
hcbruns
Asked:
hcbruns
  • 2
  • 2
1 Solution
 
Patrick MatthewsCommented:
Hermann,

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
Else
    MsgBox "Cannot determine file type; ActiveDocument not saved yet"
End If

Open in new window


Patrick
0
 
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?

Hermann
0
 
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).

Patrick
0
 
hcbrunsAuthor Commented:
Thanks, Patrick!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now