Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to recognize the difference among Excel 97 files, Excel 2000 files, and Excel 2002 files by using Visual C++ 6.0

View products that this article applies to.

This article was previously published under Q269168

↑ Back to the top


The Microsoft Excel 2000 file format and the Excel 2002 file format are the same as the Excel 97 file format with minor exceptions. One of the new additions to the Excel 2000 file format and to the Excel 2002 file format is a record that lets you detect when a file is saved with Excel 2000 or with Excel 2002 instead of with Excel 97. You use Microsoft Visual C++ 6.0 to detect the version of Excel that the file is saved with.

↑ Back to the top

More information

The record ID is 0x1C0. If this record is found in the Workbook stream, then the file is written by Excel 2000 or by Excel 2002. This is true unless the files is saved down for compatibility. Then, you can use code from the article that is mentioned in the "References" section to determine the version.

The following code demonstrates how this might be used:
    int IsExcel9(WCHAR *wcFilename) {

        // Open document as an OLE compound document...
        HRESULT hr;
        IStorage *pStg = 0;
        hr = ::StgOpenStorage(wcFilename, 0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStg);
        if(FAILED(hr)) return 0;
        // Now, get the Workbook stream
        IStream *pStm;
        WCHAR *wcBookStm = L"Workbook";
        hr = pStg->OpenStream(wcBookStm, 0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE , 0, &pStm);

        if(FAILED(hr)) {
            return 0;

        char buf[32000];
        DWORD dwRead;
        short id, len;

        for(;;) {
            // Read id & len first...
            HRESULT hr = pStm->Read(&id, 2, &dwRead);
            if( (FAILED(hr)) || (dwRead != 2) ) break;
            pStm->Read(&len, 2, &dwRead);
            if(dwRead != 2) break;
            if((id == 0) && (len == 0)) break;

            // Check for XL9File record
            if(id == 0x1c0) {
                return 1;

            // Eat record...
            if(len > 32000) len = 32000;
            pStm->Read(buf, (long)len, &dwRead);
            if((DWORD)len != dwRead) break;

        // Cleanup
        return 0;

↑ Back to the top


178605� How to determine the version of a Microsoft Excel workbook

↑ Back to the top

Keywords: KB269168, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 269168
Revision : 8
Created on : 1/27/2007
Published on : 1/27/2007
Exists online : False
Views : 348