ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Late Binding (https://www.excelbanter.com/excel-programming/411897-late-binding.html)

atpgroups

Late Binding
 
I have a project which links to either of two other packages.
Depending on which package is being used the alternative package will
not be installed and/or will not be selected in the VBA "References"
list.

I have created wrapper classes to selectively act on objects of
classes from each of the other applications but I am still having
problems with "User defined type not defined"

The problem arises any time I try to Dim a variable as a type defined
by one of the external applications even if the code will never run
through that area (Of course the compiler/parser has no way of knowing
that)

Is there any way to have conditional Dim-ing? Should I instead be
declaring as objects and then creating using CreateObject rather than
"Dim O as New clsRandomObjectWhichMightNotExist"

Any pointers or guidelines?

Peter T

Late Binding
 
If you may or may not be able to use Early Binding why not be done with it
and use Late Binding. Change related object declarations to "As Object' and
use CreateObject.

For developing, set the references and revert to Early Binding methods to
get the intellisense, and re-adapt to Late Binding when done.

Regards,
Peter T


"atpgroups" wrote in message
...
I have a project which links to either of two other packages.
Depending on which package is being used the alternative package will
not be installed and/or will not be selected in the VBA "References"
list.

I have created wrapper classes to selectively act on objects of
classes from each of the other applications but I am still having
problems with "User defined type not defined"

The problem arises any time I try to Dim a variable as a type defined
by one of the external applications even if the code will never run
through that area (Of course the compiler/parser has no way of knowing
that)

Is there any way to have conditional Dim-ing? Should I instead be
declaring as objects and then creating using CreateObject rather than
"Dim O as New clsRandomObjectWhichMightNotExist"

Any pointers or guidelines?




atpgroups

Late Binding
 
On 2 Jun, 16:38, "Peter T" <peter_t@discussions wrote:
Change related object declarations to "As Object' and
use CreateObject.


I have since found that that isn't as painful as I feared, and I am
part way through doing it (This is a _big_ excel macro),
I found that the declaration CLSIDs are all listed together in Regedit
(unless there is an easier way?) and it is only the dim O as new lines
that need changing.
The vast array of enumerated types are proving annoying, but no worse
than that.

Thanks for the confirmation that I am on the right track.


All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com