Finding the file type of a document

L

Larry

Sorry for repeating this question which I asked at the newusers group,
but I realize this is a vba question.

How can I tell if the file format type of a document is either Word 97
or Word 6.0/95? Consulting the Save As Type box in the Save As only
occasionally gives the correct result.

It seems there ought to be a vba way to do this, but it's tricky. For
example, there's the SaveFormat property, but MsgBox
ActiveDocument.SaveFormat returns 0 for all Word documents, whether they
are Word 97 or Word 6.0/95. So that's no help.

Then there's the FileConverter, but I can't find a way to find what is
the FileConverter for a particular document. For example, this prints
out a list of all the FileConverters in the FileConverters collection,

Dim fc as FileConverter
For Each fc In FileConverters
If fc.CanSave = True Then
Selection.TypeText fc.SaveFormat & vbCr & fc.FormatName & vbCr & vbCr
End If
Next fc

Then there's this, which I got by recording a SaveAs in which the Save
As Type was Word 6.0/95:

ActiveDocument.SaveAs FileFormat:=111

Yet I can't figure how to use this number in an If Then statement to see
if the FileFormat for the ActiveDocument is 111.

Thanks for any help,
Larry
 
J

Jonathan West

Hi Larry

Take a look at the following article

Getting access to the Document Properties of a Word file
http://www.mvps.org/word/FAQs/MacrosVBA/DSOFile.htm

If you download the templates & DLLs associated with the article, you will
be able to list the various properties of a folder full of files. The
Application property indicates which version of Word created the file. Each
version of Word from Word 6 onwards gives a different value for this
property.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
J

Jonathan West

Larry said:
Hi Jonathan,

Thanks. I tried it out. It works. However creating a list of all the
documents in the folder is more than I want. I wonder if there is a
simpler way to get just the information on the document I'm interested
in, by clicking on the document's icon or from within the document
itself.

The code for the template is open, you can extract the part of it you want
for your own purposes. In fact, if you have VB6, the dsofile downlod
includes a small demo application in VB6 which allows you to browse to a
file and look at its properties.
Also, since this "Application name" property is available, why isn't it
in the Properties dialog box? And is it available in vba?

I've no idea why it isn't available in the properties dialog or direct from
VBA. I assume it is because as soon as you re-save a document in Word, the
application property is set to the version of Word you are using.
Also, for documents that are in Word 6.0/95 format the macro says
"Microsoft Word for Windows 95"

I suspect that documents last edited using Word 6 rather than Word 95 will
say "Microsoft Word for Windows 6.0". But I don't have a copy of Word 6 to
hand to try that out.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
L

Larry

Jonathan,

Ok, I'll play around with it to try to extract the application name
property and make it into a macro that will be more practical for me.

It's surprising that Word doesn't provide a straightforward means of
determining what the file format of a Word document is.

Thanks again,
Larry
 
J

Jonathan West

Larry said:
Jonathan,

Ok, I'll play around with it to try to extract the application name
property and make it into a macro that will be more practical for me.

It's surprising that Word doesn't provide a straightforward means of
determining what the file format of a Word document is.

The general idea is that the Word object model works the same way anyway, so
you don't need to know. In practice it's never *quite* as simple as that ...

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
J

Jezebel

This seems a very complicated way to go about it. From your description,
it's
not the format the file had when opened that matters, it's the format you
use when you save it.

Why not just set the default FileSave format (Tools > Options > Save) to
Word 6? Or to force the issue, write your own FileSave function.
 
J

Jezebel

I don't understand your distinction between "format the file had when
opened" and "form I use when I save it." I start with a Word 97
document, and save it as a Word 6 document.

My point was simply that it is (or should be) irrelevant what format the
file had when you opened it - Word 6, 7, 10, HTML, RTF, whatever. What
you're concerned about is the format with which it is saved - You need to
make sure it is saved in Word 6 format.

But sometimes, though I thought the change of file
type had occurred, in fact it hadn't.

This sounds like a bug in your code. If you tell Word to save a file as Word
6, then that's what it should do. It's not affected by the format the file
had when you opened it; and you can't issue the save instruction
differently: either you tell Word to save it as Word 6 or you don't.
 
L

Larry

Thanks. But now I'm even more confused. :) The KB articles, such as
the one below, describe a converter as _saving_ a Word 97 document as a
Word 6 document (that is, by adding Word 6.0/95 to the list of file
formats in the Save As Type window in the Save As dialog box), while the
converter you've shown me allows Word 6 to read (and presumably edit?) a
Word 97 document. Clearly the converter you've shown me is the way to
go, this would make the saving in the new file type unnecessary; the
user just transfers the Word 97 documents back and forth between the two
machines.

Microsoft Knowledge Base Article - 171684
WD97: Differences Between RTF and Binary Export Converter

Larry



Hi Larry

why don't you just install the Word 97/2000 Converter for Word 6?
http://download.microsoft.com/download/word2000/converte/1/WIN98/EN-
US/wrd97cnv.exe
 
L

Larry

In any case, the converter Martin recommended works nicely. Now it's
not necessary to do anything special to save the Word 97 document as a
Word 6 document. Neat.

Thanks again.

Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top