"Invalid Data Format" Referencing File that Contains Procedure

Last reviewed: July 29, 1997
Article ID: Q114226
The information in this article applies to:
  • Microsoft Visual Basic Programming System, Applications Edition, version 1.0

SYMPTOMS

In a Visual Basic module, when you use the Browse dialog box to reference a file created in another application that contains a Visual Basic procedure, you receive the following error message:

   Invalid data format

CAUSE

This is by design. You cannot, for example, reference a Microsoft Excel workbook file that contains a Visual Basic module, from a Visual Basic module in a Microsoft Project project file.

WORKAROUND

To run a procedure from a Visual Basic module in one application (App1) that is contained in a file created by another application (App2), you can use the methods and properties of the object library exposed by the application that was used to create the Visual Basic procedure (App2).

For example, to run a macro from a Visual Basic module in Microsoft Excel that is contained in a Microsoft Project project file, do the following:

  1. In a new module in Microsoft Excel, choose References from the Tools menu.

  2. From the Available References list, select the Microsoft Project 4.0 Object Library check box, and choose OK.

  3. In the new module, enter the following:

       Sub Run_Proj_Macro()
          ' Dimension variable Proj as object type
          Dim Proj As Object
          ' Set Proj equal to Microsoft Project application object
          Set Proj = MSProject.Application
          ' Open project file that contains macro
          ' Note this command is not necessary to run a global macro
          Proj.FileOpen "C:\WINPROJ\PROJECT1.MPP"
          ' Run macro
          ' Replace MACRONAME with the name of the macro you want to run
          ' PROJECT1 and Module1 are not necessary but distinguish
          ' Between multiple macros with the same name
          Proj.Macro "[PROJECT1]Module1!MACRONAME"
          ' Quit Microsoft Project
          Proj.Quit
       End Sub
    
    
Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided "as is" and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the Visual Basic "User's Guide."

MORE INFORMATION

In a Visual Basic module in Microsoft Excel, you can use the Browse dialog box to reference another workbook file (*.XLS) or an add-in file, (*.XLA) that contains a Visual Basic procedure.

In a Visual Basic module in Microsoft Project, you can use the Browse dialog box to reference another project file (*.MPP) that contains a Visual Basic procedure.

You can reference a toolbar file, (*.TLB) or an object library file (*.OLB) from a Visual Basic module in either Microsoft Excel or Microsoft Project.

Keywords          : kbcode kberrmsg kbprg
Version           : 1.00
Platform          : WINDOWS


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


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.

Last reviewed: July 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.