View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Dumb early binding question

As others have pointed out, in order to use Early Binding, you have to set a
reverence to the library you wish to use. Then you can declare your object
variable as the types you wish use. e.g.
Dim OApp as Outlook.Application
'Assuming this is in Excel VBA, you already have a reference to the Excel
library, so this will work.
Dim WS As Worksheet

You now get the benefit of Intellisense, as the compiler knows the possible
methods/properties etc of the objects you are using.
If you want to use "With Events", you must use early binding.
Also, early binding ties you to a specific version of the library, to some
extent. AFAIK Excel (and other apps) will update the references to new
versions if available, but not update to older versions. If you need you
code to work on multiple versions of the same application, reference and
compile on the oldest version, or use late binding.

You can still write
Dim OApp as Object
but it is a waste, as the compiler now cannot tell which object you are
referring to, your reference serves little purpose.

Using late binding (i.e. no reference set) everything can only be declared
"Object"
Dim OApp as Object

How you instantiate your variables is a separate question.
"GetObject" uses an existing instance of the object.
"CreateObject" starts a new instance your object, if possible. You cannot
create multiple instances of some object (Outlook.Application,
Illustrator.Application, amongst others).
"New" basically the same as CreateObject, apart from some obscure
differences in which initialisation code runs, AFAIK.

NickHK

"Nicole Seibert" wrote in message
...
Okay... here goes:

Do you have to use CreateObject with set in early binding? For instance,

I
have this lovely bit of code:

Set OutApp = Outlook.Application
Set xl = Excel.Application
Set data = xl.Workbooks("Time Exception Master Data")

Is this consider early binding? Should I instead say "Get" and then the
document path? I am confused.

Thanks,
Nicole