Errors of Adding OWC10 Spreadsheet reference

B

Bula

I use the following code to add the owc10 reference to my project. It
always leads errors on some computers. Your help is highly
appreciated

Dim ref As Object, HasOWC10 As Boolean
For Each ref In ThisWorkbook.VBProject.References
If ref.Name = "OWC10" Then
HasOWC10 = True
End If
Next
If HasOWC10 = False Then ThisWorkbook.VBProject.References.AddFromFile
("C:\Program Files\Common Files\Microsoft Shared\Web Components
\10\OWC10.DLL")

For the computers with such error, I also can not add the reference
mannually IN VBA environment by clicking:

Tools - References - Browse (C:\Program Files\Common Files\Microsoft
Shared\Web Components\10\OWC10.DLL) - OK

gzhu
 
T

Tyla

The general problem is that the code references a specific file in a
specific place. Different versions of Excel will have a different name
for "OWC10".
A somewhat more general way of doing this is to use the ".GUID'
property of VBProject.References. This should always work in theory
since the GUID value should be stable across various versions of
Excel. There has been at least on exception to this in Microsoft's
history, but it's a generally much better guess than file name.
The next issue, of course, is that you're trying to assert a reference
based on hard-wired file name and path. This is unlikely to work
across different versions of Excel, and will fail within the same
version of Excel depending on where they installed the program. One
example on the Web about doing this is http://www.vbaexpress.com/kb/getarticle.php?kb_id=267
-- and there are no doubt many others.
HTH

/ Tyla /
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top