Working with Multiple Applications to Get the Job Done

 < Day Day Up > 



There are times when simply working within Excel is too restrictive. That's the main reason you bind your workbook to additional applications.

Throughout this chapter, you learned how to access different applications. The Shell function can be used to open programs that fall outside of Microsoft Office Suite. However, when working within the Microsoft Office Suite you need to access the different Application objects. It's possible to reference a new Application object using late binding; however, it's recommended that you use early binding when programming your procedures.

To automate the objects in another application, you create an object variable referring to the target application or an object in the application. You can use early binding or late binding to establish the link between VBA and the other application's objects. Early binding requires that you establish a reference to the target application's object library, and you must declare any object variables that refer to the target objects using their correct type. If you declare the object variables as the generic Object type, VBA uses late binding.

Early binding produces code that executes faster than late binding, and you can get information on the target application's objects using the Object Browser and the shortcut tips that automatically appear as you type your code. Syntax checking and type checking is also performed as you code, so you are less likely to get errors when the code executes than with late binding.

You must use the CreateObject or the GetObject function to create an object variable reference to the target application when using late binding. You can use the same functions when early binding, but it's more efficient to use the New keyword. However, if you want to test for an open instance of another application at run time, GetObject can be used with early binding as well.

The techniques presented in this chapter allow you to create powerful programs that tap into the unique abilities of different products. The user remains in a familiar environment such as Excel, while the code ranges across any product that has a type library and exposes its objects to VBA.



 < Day Day Up > 



Microsoft Excel 2003 Programming Inside Out
Microsoft Office Excel 2003 Programming Inside Out (Inside Out (Microsoft))
ISBN: 0735619859
EAN: 2147483647
Year: 2006
Pages: 161

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net