KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q157721: HOWTO: Determine FileFormat Values for Excel SaveAs Method

Article: Q157721
Product(s): Microsoft FoxPro
Version(s): 
Operating System(s): 
Keyword(s): kbinterop kbExcel
Last Modified: 20-AUG-1999

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0, 6.0 
-------------------------------------------------------------------------------

SUMMARY
=======

Visual Basic for Excel Help often specifies constant names rather than values to
be used in calling object methods. When performing OLE Automation from Visual
FoxPro, FoxPro does not understand these constants and, therefore, requires
their initial values.

Below are the steps used to determine what the constant value is for a specific
file format to be used for the FileFormat portion of the SaveAs method.

MORE INFORMATION
================

1. Create a worksheet in Excel and save it in the format that you want. Make
  sure that you close the file before continuing.

2. Issue the following commands in Visual FoxPro:

        * First get an object reference to the Excel application
        oXL = CREATEOBJECT("Excel.Application")  && starts excel

        * Open the worksheet created in step 1 (be sure to include
        * the full path and file name
        oXL.WorkBooks.Add("myfile.xls")

        * Retrieve the FileFormat
        nFileFormat = oXL.WorkBooks(1).FileFormat

        * Save the file under a new name with the same format
        oXL.WorkBooks(1).SaveAs("new.xls",nFileFormat)

        * Quit Excel
        oXL.Quit

        * Release the object reference
        RELEASE oXL

Additional query words:

======================================================================
Keywords          : kbinterop kbExcel 
Technology        : kbVFPsearch kbAudDeveloper kbVFP300 kbVFP300b kbVFP500 kbVFP600
Issue type        : kbhowto

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.