Article ID: 147392 - View products that this article applies to.
This article was previously published under Q147392
In the versions of Microsoft Excel listed at the beginning of this article, you can use a Visual Basic for Applications macro to run other Windows and MS-DOS applications and procedures. The macro code in Microsoft Excel continues to execute even after the external procedure has been initiated. You must write code to handle delays if Microsoft Excel is to wait for the output from the outside procedure.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Creating the ModuleBefore you use the examples in this article, follow these steps:
Example 1: Creating a FlagFor the macro code in example 1 to work correctly, you need to make your custom application create a flag when it has completed execution. In the following example your custom application should create a text file at C:\Flag.txt to act as this flag.
Example 2: Using an Intermediate File to Avoid a Sharing ViolationThis example uses an intermediate file to allow the MS-DOS DIR command to complete and close the output before Microsoft Excel attempts to open it. If this method were not used, the Workbooks.Open method would generate a sharing violation by attempting to open the output while it was still being written.
While the example below illustrates one use of this procedure, you could apply the same method to any MS-DOS or Windows application that generates an output file that can be read by Microsoft Excel.
For additional information, please see the following articles in the Microsoft Knowledge Base:
129796For more information about Shell function in Microsoft Excel 97, click the Index tab in Visual Basic for Applications Help, type the following text
(http://support.microsoft.com/kb/129796/EN-US/ )How to Determine When a Shelled 32-bit Process Has Terminated
(http://support.microsoft.com/kb/96844/EN-US/ )How to Determine When a Shelled 16-bit Process Has Terminated
and then double-click the selected text to go to the "Shell function" topic.
For more information about the Shell function in Microsoft Excel 7.0, click Answer Wizard on the Help menu and type:
tell me about the Shell function
Article ID: 147392 - Last Review: October 11, 2006 - Revision: 2.3
Contact us for more help