Hi Malcolm
1. If it's a firm-wide situation then someone, somewhere, has messed up
with the overall strategy of the roll out.
This might be true for small or medium sized companies. But in large
companies (1000+), you always have a heterogenous environment
up to some extent, no matter what policies/strategies you have. You
cannot switch 5000 users to Office 2003 immediately, a migration
always takes time (during which all users should be able to work
as usual)...
The (software-)world is getting better, but it is still far from being
perfect ;-)
2. If one is wanting a return value from one of these calls into the
Unknown then surely the best thing is not to use Application.Run but to
have the called routines shoved into an Active-X DLL or Exe and then call
that library.
After all, with use of the COM interface one doesn't need to know the
location of the library and also one can have return values or objects
coming back to the calling routine.
In all honesty, I cannot see a single reason for using Application.Run in
this day and age. Perhaps in Word95 days (when it really was a macro
language) then I would totally agree.
Agreed, but only up to a certain extent. In the very low-level view, COM
supports two ways of accessing an object's functionality. The first is the
use
of the IUnknown-interface and a call to its QueryInterface method, the other
is the use of IDispatch and a call to Invoke-method. While the first one
corresponds to the early-binding approach, the second one corresponds
to late-binding, where an object does not have to know *anything* about
the destination object but the name of the method to call or the property to
set/get. VBA can only work the way it does because of the IDispatch-
mechanism. Well, although VBA hides this situation mostly from the
programmer,
there are some points where the concept bubbles up to the surface.
Application.Run is such a thing, it corresponds almost 1:1 to the Invoke-
method of the IDispatch-interface.
The reason why I don't entirely agree with your position is that I've
seen lots of examples of problems with the VBA-reference-approach.
I'm sure that a lot of "corporate" VBA-programmers even nowadays run
into situations where a project referencing an ActiveX-component works
perfectly on one installation (e.g. Office 97 on WinME) but has a problem
with
finding the referenced component on another (e.g. Office XP on WinXP).
Personally, I ran into such situations various times. An example is the cool
CalendarControl installed with Access. Every single time, switching from the
static reference-approach to late-binding saved the day...
There is another point, though. While the reference-way always forces
the programmer to concentrate on specific members of objects, late-binding
with e.g. Application.Run lets you reuse the same code for different
purposes. Although the following example does not make much sense,
I hope you see what my point is:
Consider the following situation where you have 2 different functions
for calculating the area of a triangle (e.g. CalcArea3) and a rectangle
(e.g. CalcArea4), both with two parameters. There is a variable (edges),
which holds the number of edges. The standard way to calculate
the area would be an if-statement like this:
If edges = 3 Then
area = CalcArea3(value1, value2)
ElseIf edges = 4 Then
area = CalcArea4(value1, value2)
End If
Now, consider the solution using Application.Run:
area = Application.Run("CalcArea" & edges, value1, value2)
This might not seem to be spectacular, but when the number of
different but related functions rises, this results in a considerable
decrease of code lines. (Note that error handling and/or bounds
checking and stuff still needs to be addressed, though)
Note that I don't want to push people to using Application.Run (beware!!!).
I'm just saying that you might not want to restrict yourself to never using
it at all...
Anyway, I am sure that countless number of others will happily flame me
for this comments and thoughts.
No need for flaming, just expressing different points of view which makes
the whole newsgroup-thing so interesting ;-)
Cheers,
Martin