Communicating with Other Applications

23.08.2021

Apart from working with FlexPro data, you might want your application to exchange data with other applications, such as Microsoft Excel. You can communicate with other applications by using Automation (formerly OLE Automation).

Automating FlexPro From Within Another Application

With Automation, you can return, edit and export data by addressing objects, properties and methods of another application. Application objects that can be addressed by another application are called Automation objects.

To make FlexPro available to another Automation application, the first thing you have to do is create a reference to the FlexPro Application object. In Visual Basic, you use the function CreateObject or GetObject to return a reference to the FlexPro Application object. In a Microsoft Excel procedure, for example, you could use the following statement.

Set app = CreateObject("FlexPro.Application")

This statement makes the Application object in FlexPro available for Automation. You can control FlexPro by using the objects, properties and methods of the FlexPro Application object. The following statement, for example, creates a new FlexPro database.

app.Databases.Add

The function CreateObject starts a FlexPro session that is not closed by Automation if the object variable addressing the Application object becomes invalid. If the object reference is set to the keyword Nothing, FlexPro is not closed. Instead, use the Quit method to close the FlexPro application. In the following example, the FlexPro start path is shown. The Quit method is used to close the new instance of FlexPro after the start path has been displayed.

Set app = CreateObject("FlexPro.Application")

MsgBox app.Path

app.Quit

Automating Another Application From Within FlexPro

If you want to use Automation from within FlexPro to exchange data with another application, the function CreateObject or GetObject provides a reference to the application. Then, use the objects, properties and methods of the other application to add, change or delete data. When you have finished making your changes, close the application. In the following FlexPro example, the Microsoft Excel start path is displayed. You can use the Set statement with the Nothing keyword to delete an object variable. This has the same effect as closing the application.

Set myobject = CreateObject("Excel.Application")

MsgBox myobject.Path

Set myobject = Nothing

For information on referencing an object library and using the objects it contains, go to Understanding Automation and Set a Reference to a Type Library.

Share article or send as email:

You might be interested in these articles