Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Dumb early binding question

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Dumb early binding question

Early binding is when you tell the compiler up front what kind of objects
you will be using. This is done in the VBE through Tools | References...

In your example, use the above menu item to see if you have references to
Excel and Outlook. That will tell you whether you are or are not using
early binding.

[Actually, if you get set outapp=outlook.application to compile you are
using early binding. But, the Tools | References... is the first place I
would look.]

With early binding you can use set xl=excel.application or you can use
getobject and/or createobject. With late binding since the compiler doesn't
know the type of xl, you must use getobject and/or createobject.

You may want to see

Early and Late Binding
http://msdn2.microsoft.com/en-us/library/0tcf61s1.aspx

CreateObject Function (Visual Basic)
http://msdn2.microsoft.com/en-us/library/7t9k08y5.aspx

GetObject Function (Visual Basic)
http://msdn2.microsoft.com/en-us/library/e9waz863.aspx

While in most cases early binding is the preferred way to go, there are
instances when late binding is better. But, for learning purposes, early
binding is definitely the correct approach.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Dumb early binding question

Early / late binding is more a question of how you define your variables.

Dim objOL as Object 'late
Dim objOL as Outlook.Application 'early

Set objOL = CreateObject("Outlook.Application") 'same for both

Benefits of early binding include getting Intellisense when writing your code: drawbacks include having to add a refence to the
library in your project.

see:
http://msdn.microsoft.com/archive/de...html/SF7A4.asp
http://www.dicks-clicks.com/excel/olBinding.htm


Tim

"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



  #4   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Early and Late Binding Vba Excel VJ Excel Programming 7 April 7th 05 06:05 PM
Error or Unexpected Behavior with Office Automation when you use early binding Barb[_5_] Excel Programming 3 September 15th 04 03:17 PM
VBA References - when is Office Object Library Reference set? Best practice re. Early/Late binding ... AndyB Excel Programming 5 April 22nd 04 02:11 PM
EARLY binding or LATE binding ? jason Excel Programming 6 February 26th 04 04:57 PM
Early vs Late Binding - Word John Wilson Excel Programming 6 November 13th 03 03:21 PM


All times are GMT +1. The time now is 04:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"