Microsoft KB Archive/114226

= "Invalid Data Format" Referencing File that Contains Procedure =

PSS ID Number: 114226

Article Last Modified on 1/17/2001

-

The information in this article applies to:


 * Microsoft Visual Basic for Applications 1.0

-



This article was previously published under Q114226



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:  In a new module in Microsoft Excel, choose References from the Tools menu. From the Available References list, select the Microsoft Project 4.0 Object Library check box, and choose OK.  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: KB114226

Technology: kbVBA100 kbVBASearch kbZNotKeyword3 kbZNotKeyword6

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2004 Microsoft Corporation. All rights reserved.