Thanks Hans.
Appreciate it.
I expect after I re read a fewtimes I will finally get what I am missing
Alan
To Object or not to object
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: To Object or not to object
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- 5StarLounger
- Posts: 964
- Joined: 08 Nov 2012, 17:54
Re: To Object or not to object
Hello Alan,
Here are what I think IMHO are the two best links about this.
https://support.microsoft.com/en-au/hel ... automation" onclick="window.open(this.href);return false;
https://wordmvp.com/FAQs/InterDev/Early ... inding.htm" onclick="window.open(this.href);return false;
Hans' answers were great!
HTH
Lisa
Here are what I think IMHO are the two best links about this.
https://support.microsoft.com/en-au/hel ... automation" onclick="window.open(this.href);return false;
https://wordmvp.com/FAQs/InterDev/Early ... inding.htm" onclick="window.open(this.href);return false;
Hans' answers were great!
HTH
Lisa
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: To Object or not to object
Thanks Lisa, I hadn’t seen those 2, I’ll take a look
Alan
Alan
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
To Object or not to object? Not a lot in it I expect
Hi
This is my attempt to Summarise how we Dim the VBIDE things…. So I think it summarises what we have been discussing here, and is an attempt to answer the original question …maybe… sort of… :-) … for now it sounds convincing to me
Something going by the name of Automation Object Linking and Embedding, or Automation OLE or Automation is part of some very fundamental software things going way back that Microsoft did: It is especially good apparently at making it possible to run some application in others.
There are two ways to use Automation to programmatically control another application. These are referred to as Early Binding or Late Binding
For Early Binding you need to set a reference in your project to the application you want to manipulate. However this does not necessarily mean that you can manipulate the application.
Possibly then , ( I suggest, I don’t know for sure) , that to set a reference does not always mean that you have Early Binding.
( The advantages we have discussed of using Early Binding rather than Late Binding are
_ Access to the application's built-in constants
_ Ability to declare to the object types of the application leading to
__Intellisense
__Syntax checking at Compile
_ There maybe some minor efficiencies to do with how the computer handles Early Binding compared to Late Binding
_ You may have access to the application's object model via the Object Browser and VBA Help )
If you are attempting to access the Class of some application, then that could well mean that you are trying to programmatically control another application. In other words you want to do Automation . In oher words you need to do Binding.
Then to do this, for the Early Binding case you would tend to
_(i) check the reference,
_(ii) Dim a variable to the objects Class
_(iii) then you need to Instantiate an instance using the class ( you could argue that _(i) and / or _(ii) is the first part of this )
To Instantiate you can
either
__ use the New stuff in your Set line
or
__ use the CreateObject(“….”,”…. ”) thingy in your Set line
( The Diming step in _(ii) could be regarded as meaning that you are Early Binding. I would suggest that that is debatable. )
For Late Binding you only have the possibility to use the CreateObject(“….”,”…. ”) thingy in your Set line, and as you do not have the object types available to Dim. You must Dim As Object
If you try either of those Binding ways in the case of the VBIDE being discussed in this Thread, then they will fail. The short answer to why that is, is that Microsoft do not allow Automation in this case. The in depth explanation of this is galaxies beyond my level of computer understanding, but it is something like the Component Object Model used by Microsoft to allow this Automation is not “exposed”
A common circumstance for Microsoft to do this forbidding is when something is dependant on something else for its existence, as is the case of the things to do with the VB Editor
My conclusion is that Late Binding, and possibly Early Binding also, is not possible in for VBIDE
We can do, ( as far as I can tell all ) the same programming in the VB Editor with or without a reference to Microsoft Visual Basic for Applications Extensibility 5.3, ( Class Name: VBIDE ) . In other words .. We can do, ( as far as I can tell all ), the same programming in the VB Editor with or without “Object” as the Dim )
( If we check the reference then we can Dim to an object type from VBIDE, and have the advantages mentioned above. )
As always, I do not know if this summary is correct. It could be wrong. It’s my best guess currently. Its based on what I have learnt from participation in this Thread, and through reading an awful lot and understanding very little..
Alan
Ref
http://www.eileenslounge.com/viewtopic. ... 20#p244221" onclick="window.open(this.href);return false;
http://www.eileenslounge.com/viewtopic. ... 20#p244202" onclick="window.open(this.href);return false;
https://docs.microsoft.com/en-us/dotnet ... e-binding/" onclick="window.open(this.href);return false;
https://support.microsoft.com/en-au/hel ... automation" onclick="window.open(this.href);return false;
http://www.excelfox.com/forum/showthrea ... ibraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques?p=10971#post10971
https://www.excelforum.com/excel-progra ... rs-it.html" onclick="window.open(this.href);return false;
This is my attempt to Summarise how we Dim the VBIDE things…. So I think it summarises what we have been discussing here, and is an attempt to answer the original question …maybe… sort of… :-) … for now it sounds convincing to me
Something going by the name of Automation Object Linking and Embedding, or Automation OLE or Automation is part of some very fundamental software things going way back that Microsoft did: It is especially good apparently at making it possible to run some application in others.
There are two ways to use Automation to programmatically control another application. These are referred to as Early Binding or Late Binding
For Early Binding you need to set a reference in your project to the application you want to manipulate. However this does not necessarily mean that you can manipulate the application.
Possibly then , ( I suggest, I don’t know for sure) , that to set a reference does not always mean that you have Early Binding.
( The advantages we have discussed of using Early Binding rather than Late Binding are
_ Access to the application's built-in constants
_ Ability to declare to the object types of the application leading to
__Intellisense
__Syntax checking at Compile
_ There maybe some minor efficiencies to do with how the computer handles Early Binding compared to Late Binding
_ You may have access to the application's object model via the Object Browser and VBA Help )
If you are attempting to access the Class of some application, then that could well mean that you are trying to programmatically control another application. In other words you want to do Automation . In oher words you need to do Binding.
Then to do this, for the Early Binding case you would tend to
_(i) check the reference,
_(ii) Dim a variable to the objects Class
_(iii) then you need to Instantiate an instance using the class ( you could argue that _(i) and / or _(ii) is the first part of this )
To Instantiate you can
either
__ use the New stuff in your Set line
or
__ use the CreateObject(“….”,”…. ”) thingy in your Set line
( The Diming step in _(ii) could be regarded as meaning that you are Early Binding. I would suggest that that is debatable. )
For Late Binding you only have the possibility to use the CreateObject(“….”,”…. ”) thingy in your Set line, and as you do not have the object types available to Dim. You must Dim As Object
If you try either of those Binding ways in the case of the VBIDE being discussed in this Thread, then they will fail. The short answer to why that is, is that Microsoft do not allow Automation in this case. The in depth explanation of this is galaxies beyond my level of computer understanding, but it is something like the Component Object Model used by Microsoft to allow this Automation is not “exposed”
A common circumstance for Microsoft to do this forbidding is when something is dependant on something else for its existence, as is the case of the things to do with the VB Editor
My conclusion is that Late Binding, and possibly Early Binding also, is not possible in for VBIDE
We can do, ( as far as I can tell all ) the same programming in the VB Editor with or without a reference to Microsoft Visual Basic for Applications Extensibility 5.3, ( Class Name: VBIDE ) . In other words .. We can do, ( as far as I can tell all ), the same programming in the VB Editor with or without “Object” as the Dim )
( If we check the reference then we can Dim to an object type from VBIDE, and have the advantages mentioned above. )
As always, I do not know if this summary is correct. It could be wrong. It’s my best guess currently. Its based on what I have learnt from participation in this Thread, and through reading an awful lot and understanding very little..
Alan
Ref
http://www.eileenslounge.com/viewtopic. ... 20#p244221" onclick="window.open(this.href);return false;
http://www.eileenslounge.com/viewtopic. ... 20#p244202" onclick="window.open(this.href);return false;
https://docs.microsoft.com/en-us/dotnet ... e-binding/" onclick="window.open(this.href);return false;
https://support.microsoft.com/en-au/hel ... automation" onclick="window.open(this.href);return false;
http://www.excelfox.com/forum/showthrea ... ibraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques?p=10971#post10971
https://www.excelforum.com/excel-progra ... rs-it.html" onclick="window.open(this.href);return false;
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- Administrator
- Posts: 78574
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: To Object or not to object
Some examples; all assume that you are creating and running the code in Excel.
1) Set a reference to the Microsoft Word n.0 Object Library
Dim x As Word.Application
Set x = New Word.Application ' or CreateObject(Class:="Word.Application")
This is early binding, since x is a Word application object. You can use IntelliSense and syntax checking for x.
2) Set a reference to the Microsoft Word n.0 Object Library
Dim x As Object
Set x = CreateObject(Class:="Word.Application")
Although you set a reference to the Word object library, this is late binding, since x is a generic object. You cannot use IntelliSense with x, nor can you check the syntax for x.
3) Do NOT set a reference to the Microsoft Word n.0 Object Library
Dim x As Object
Set x = CreateObject(Class:="Word.Application")
This is obviously late binding. You cannot use IntelliSense with x, nor can you check the syntax for x.
Similarly:
4) Set a reference to Microsoft Visual Basic for Application Extensibility 5.3
Dim x As VBIDE.CodeModule
Set x = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
This is early binding, since x is a VBIDE.CodeModule object. You can use IntelliSense and syntax checking for x.
5) Set a reference to Microsoft Visual Basic for Application Extensibility 5.3
Dim x As Object
Set x = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
Although you set a reference to the VBIDE object library, this is late binding, since x is a generic object. You cannot use IntelliSense with x, nor can you check the syntax for x.
6) Do NOT set a reference to Microsoft Visual Basic for Application Extensibility 5.3
Dim x As Object
Set x = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
This is obviously late binding. You cannot use IntelliSense with x, nor can you check the syntax for x.
...
1) Set a reference to the Microsoft Word n.0 Object Library
Dim x As Word.Application
Set x = New Word.Application ' or CreateObject(Class:="Word.Application")
This is early binding, since x is a Word application object. You can use IntelliSense and syntax checking for x.
2) Set a reference to the Microsoft Word n.0 Object Library
Dim x As Object
Set x = CreateObject(Class:="Word.Application")
Although you set a reference to the Word object library, this is late binding, since x is a generic object. You cannot use IntelliSense with x, nor can you check the syntax for x.
3) Do NOT set a reference to the Microsoft Word n.0 Object Library
Dim x As Object
Set x = CreateObject(Class:="Word.Application")
This is obviously late binding. You cannot use IntelliSense with x, nor can you check the syntax for x.
Similarly:
4) Set a reference to Microsoft Visual Basic for Application Extensibility 5.3
Dim x As VBIDE.CodeModule
Set x = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
This is early binding, since x is a VBIDE.CodeModule object. You can use IntelliSense and syntax checking for x.
5) Set a reference to Microsoft Visual Basic for Application Extensibility 5.3
Dim x As Object
Set x = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
Although you set a reference to the VBIDE object library, this is late binding, since x is a generic object. You cannot use IntelliSense with x, nor can you check the syntax for x.
6) Do NOT set a reference to Microsoft Visual Basic for Application Extensibility 5.3
Dim x As Object
Set x = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
This is obviously late binding. You cannot use IntelliSense with x, nor can you check the syntax for x.
...
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: To Object or not to object
Thanks very much for the extra input Hans
I do appreciate it.
You seem to be saying that the definition of
Late Binding: things like cannot use IntelliSense with x , x is an object , ( cannot you check the syntax for x )
Early Binding: things like can use IntelliSense and syntax checking for x. x is an application object
With the very most greatest of respect, and I fully expect that I could be wrong, but I am just suggesting that they are typical characteristics which are mostly always true of the Bindings, possibly always true characteristics.
I cant yet quite accept that they are definitions. I have tried to make a suggestion for what I think are the definitions, that’s all
Alan
( P.s. I am in full agreement with your Early and Late Binding examples in 1) 2) and 3) I am still just struggling to accept that 4) 5) and 6) are Binding )
I do appreciate it.
You seem to be saying that the definition of
Late Binding: things like cannot use IntelliSense with x , x is an object , ( cannot you check the syntax for x )
Early Binding: things like can use IntelliSense and syntax checking for x. x is an application object
With the very most greatest of respect, and I fully expect that I could be wrong, but I am just suggesting that they are typical characteristics which are mostly always true of the Bindings, possibly always true characteristics.
I cant yet quite accept that they are definitions. I have tried to make a suggestion for what I think are the definitions, that’s all
Alan
( P.s. I am in full agreement with your Early and Late Binding examples in 1) 2) and 3) I am still just struggling to accept that 4) 5) and 6) are Binding )
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- Administrator
- Posts: 78574
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: To Object or not to object
The essential difference is: do you declare a variable to be an object of a specific type such as Word.Application, or Outlook.MailItem, or VBIDE.CodeModule etc., or as a generic Object.
If the former, the variable will have all properties, methods and events of that specific type right from the start, when you are writing the code. That is early binding.
If the latter, the variable will only have those properties etc. after you have actually set the variable to something, i.e. during runtime. That is late binding.
If the former, the variable will have all properties, methods and events of that specific type right from the start, when you are writing the code. That is early binding.
If the latter, the variable will only have those properties etc. after you have actually set the variable to something, i.e. during runtime. That is late binding.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: To Object or not to object
Thanks very much again Hans
I think in many Blogs and You tube tutorials etc, even in some books I have read things very similar to what you are saying.
I have said something very similar to others in answering forum questions in the past. Questions like .. What is Early binding? What is late Binding?
I still do not really dispute that
The issues raised in the case of the VBIDE have caused me to look a bit further into official documentation and to try to understand as much as I can a bit more in detail
As briefly as I am able, and not in my words, but in the words of Microsoft official documentation:
There are two ways to implement Automation. These are Early and Late Binding. In VBA that is what Early and Late Binding is: ways to make Automation work, if it is allowed. Automation is not possible with the VBIDE. Microsoft do not allow it
My conclusion then from that is that we cannot do Binding in the VBIDE. It errors if we try.
Alan
Edit : A final summary here... http://www.excelfox.com/forum/showthrea ... ibraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques?p=10975#post10975 https://tinyurl.com/y2u5ny4w" onclick="window.open(this.href);return false;
I think in many Blogs and You tube tutorials etc, even in some books I have read things very similar to what you are saying.
I have said something very similar to others in answering forum questions in the past. Questions like .. What is Early binding? What is late Binding?
I still do not really dispute that
The issues raised in the case of the VBIDE have caused me to look a bit further into official documentation and to try to understand as much as I can a bit more in detail
As briefly as I am able, and not in my words, but in the words of Microsoft official documentation:
There are two ways to implement Automation. These are Early and Late Binding. In VBA that is what Early and Late Binding is: ways to make Automation work, if it is allowed. Automation is not possible with the VBIDE. Microsoft do not allow it
My conclusion then from that is that we cannot do Binding in the VBIDE. It errors if we try.
Alan
Edit : A final summary here... http://www.excelfox.com/forum/showthrea ... ibraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques?p=10975#post10975 https://tinyurl.com/y2u5ny4w" onclick="window.open(this.href);return false;
Last edited by Doc.AElstein on 16 Feb 2019, 12:41, edited 4 times in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- Administrator
- Posts: 78574
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands