Distribute TreeView Control - reference error

S

SpaceCamel

I made a userform that includes a TreeView contol. Works great so now I want
to distribute it to others. But when other try to use it they get an error
because the control is not referenced. MS Common Controls 6.0 .

Is there an automatic way to make the references on other computers? What
is the best way to distribute userform controls so they work?

Thanks,
 
J

John

SpaceCamel said:
I made a userform that includes a TreeView contol. Works great so now I want
to distribute it to others. But when other try to use it they get an error
because the control is not referenced. MS Common Controls 6.0 .

Is there an automatic way to make the references on other computers? What
is the best way to distribute userform controls so they work?

Thanks,

SpaceCamel,
Yeah, that's a fun one isn't it. Many years ago I addressed this problem
by using an Open event macro attached to the file that needed the macro,
or userform, I created. The syntax for automatically setting a reference
for Excel was,
Application.VBE.ActiveVBProject.References.AddFromguid
"{00020813-0000-0000-C000-000000000046}", 1, 2

I'm not totally sure but I think one of the disadvantages to this
approach is that it sets a reference for a particular version of the
reference. Plus, as I recall it wasn't all that easy digging out the
correct guid value for the reference.

Nowadays I take a different approach. I set the reference and then send
the subject macro to the user with that reference set. I won't guarantee
that it always works, having the reference set that way should set the
necessary references on the user's PC. One problem of course is that if
the reference is not available on the user's PC, an error will occur and
as I recall, the MS Common Controls 6.0 is one of those references that
was not in my list of object library references. I had to go look for it
and if I had to do it again I'm not sure I could find it.

As a fallback, in my macros today I include the following code. Note,
that these lines of code need to be in an Open event macro or in a
separate macro that calls your main code, otherwise this check loop
won't even run. (Obviously this checking loop is set up for the Excel
library reference).

XLRef = False
For Each oRef In ThisProject.VBProject.References
If oRef.Name = "Excel" Then
XLRef = True
Exit For
End If
Next
If XLRef = False Then
MsgBox "In order for the report to be properly formatted," & vbCr _
& "a reference to the Excel object library must be set." & vbCr
& vbCr _
& "If you are unsure how to do this, contact the author or" &
vbCr _
& "your IT department for assistance.", vbCritical, MsgBxTitle &
" - Fatal Error"
Exit Sub
End If

Not sure if this helps, but perhaps it's a starting point.

John
Project MVP
 
S

SpaceCamel

Doesn't look like there is an easy answer. Somehow I thought "MS Windows
Common Controls" would be something that was common on Windows systems. Some
PC's have it and some don't. Wonder how they were installed.

Thanks for the help . I might just have to manually set it up.
=============================================
 
J

John

SpaceCamel said:
Doesn't look like there is an easy answer. Somehow I thought "MS Windows
Common Controls" would be something that was common on Windows systems. Some
PC's have it and some don't. Wonder how they were installed.

Thanks for the help . I might just have to manually set it up.

SpaceCamel,
You're welcome and thanks for the feedback. I thought the MS Common
Controls library would be on all systems also and it may be but it sure
isn't right out there in "plain sight" with the other libraries. I guess
it's part of the magic and intrigue of working with Windows.

John
 
Top