Halaman

Tampilkan postingan dengan label Office Automation. Tampilkan semua postingan
Tampilkan postingan dengan label Office Automation. Tampilkan semua postingan

Jumat, 24 September 2010

Excel Constants Enumeration

When we automate an application such as a Microsoft Office application, the calls to the properties and methods of the Office application's objects must be connected in some way to those objects. The process of connecting property and method calls to the objects that implement those properties and methods is commonly called binding.

Early Binding sets the connections between Excel and the other application early during design time, while Late Binding the connection isn't made until run time.

Early Binding has several advantages, because the Object Model of the other application is known during development, we can make use of Intellisense and the Object Browser to help write code. Late Binding does not allow us to use debugging tools, Intellisense, or Object Browser. The advantage to Late Binding is we do not have to worry about the wrong version of an object library being installed on the user's computer.

While coding for Office automation, I usually record a macro then refer to the commands into mine. We might use some constants, and for Late Binding we have to know the constants value of a constant name.

To get Excel constants enumeration:
1. Open Excel
2. Open Visual Basic Editor, then type the constants name e.g:


Sub main()
MsgBox (xlInsideHorizontal)
MsgBox (xlNone)
End Sub

Another way:
1. Open Excel
2. Open Visual Basic Editor, then press F2
3. Type the constants in the search box e.g: xlNone
4. Click Search button, we get -4142

Each Office program that supports VBA has a set of built-in constants, with numeric values that represent some state or property. These constants are usually prefixed with the initials of the source program. i.e. 'xl' for Excel, 'ol' for Outlook, 'wd' for Word.