EARLY binding and LATE binding, please explain?
to understand please an example with outllok or excel vba.
EARLY binding and LATE binding
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: EARLY binding and LATE binding
When you want to control Outlook from Excel, you can set a reference to the Microsoft Outlook Object Library in Tools | References...
That way, the Visual Basic Editor recognizes Outlook VBA commands. For example, if you type
Dim app As Outlook.
a list of properties and methods of Outlook will pop up. This is called early binding.
Advantage: you can check your syntax, and press F1 to get help about Outlook objects.
Disadvantage: the code may not work on a computer with a different version of Outlook.
To get around the disadvantage, you can remove the reference to the Microsoft Outlook Object Library.
Advantage: the code should work with all versions of Outlook.
Disadvantage: you can't check the Outlook part of the syntax, and you can't get help about Outlook objects.
This is called late binding. You'll have to change some things in the code. See this post for instructions on converting early binding to late binding.
Example of early binding:
Dim app As Outlook.Application
Dim msg As Outlook.MailItem
Set app = New Outlook.Application
Set msg = app.CreateItem(olMailItem)
And the same but using late binding:
Dim app As Object
Dim msg As Object
Set app = CreateObject("Outlook.Application")
Set msg = app.CreateItem(0)
That way, the Visual Basic Editor recognizes Outlook VBA commands. For example, if you type
Dim app As Outlook.
a list of properties and methods of Outlook will pop up. This is called early binding.
Advantage: you can check your syntax, and press F1 to get help about Outlook objects.
Disadvantage: the code may not work on a computer with a different version of Outlook.
To get around the disadvantage, you can remove the reference to the Microsoft Outlook Object Library.
Advantage: the code should work with all versions of Outlook.
Disadvantage: you can't check the Outlook part of the syntax, and you can't get help about Outlook objects.
This is called late binding. You'll have to change some things in the code. See this post for instructions on converting early binding to late binding.
Example of early binding:
Dim app As Outlook.Application
Dim msg As Outlook.MailItem
Set app = New Outlook.Application
Set msg = app.CreateItem(olMailItem)
And the same but using late binding:
Dim app As Object
Dim msg As Object
Set app = CreateObject("Outlook.Application")
Set msg = app.CreateItem(0)
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: EARLY binding and LATE binding
With early binding, you can also use the application-specific constants. With late binding, you need to use the numeric equivalents of those constants. For a workaround, that allows you to use the application-specific constants with late binding, see: http://windowssecrets.com/forums/showth ... post856372" onclick="window.open(this.href);return false;
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands