Remove/Install Reference

Hi experts

I've just changed over to a Windows 7 64-bit operating system, still running Windows 2007 (32 bit).

I have a client that is using Office 2007 in a Windows 7 32 bit environment. They have installed Microsoft Windows common controls-2 6.0 on all their users computers, ie Date-picker.

The Word templates I created references this control MSCOMCT2. I've got it installed on my 64-bit machine but it is stored in a different folder to the 32-bit machine.

64-bit strRefName = "C:\Windows\SysWOW64\mscomct2.ocx"
32-bit strRefName = "C:\Windows\System32\mscomct2.ocx"

I need to edit the tempate and supply to them, but I keep getting an error message that the object is not loaded. I've tried the line below on New/Open but it isn't working. It appears to be working (no error message), but there is no tick against the reference

Help!

Application.ActiveDocument.VBProject.References.AddFromFile strRefName

Open in new window



Any ideas how I can get this to work?
Fi69Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wdosanjosCommented:
If your code is running as 64-bit it won't be able to load the 32-bit control (or 32-bit process cannot load the 64-bit control).  Is this the behavior that you are experiencing?
Fi69Author Commented:
I actually got the control to load on Windows 64-bit via the steps I found on this website
http://angrybyte.com/windows-hacks/mscomctl-ocx-for-64-bit-windows-7-vista/

Before I did the above step, I was getting the load object error caused by the missing reference. So now it is fine on Windows 64-bit.

However, when I put the template with the reference back on the Windows 32-bit machine running Word 2007 I get the load error there. Probably because of the different file path of the reference????
Fi69Author Commented:
Sorry, the steps above, obviously I changed it to the MSCOMCT2 control rather than the MSCOMCTL that they mention.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

CodeCruiserCommented:
You have two options

1) Check if the file exists in one path or the other and use that path accordingly
     http://www.vbaexpress.com/kb/getarticle.php?kb_id=559

2) Use AddFromGUID instead of AddFromFile. You can get the GUID from registry
     http://msdn.microsoft.com/en-us/library/aa141620(v=office.10).aspx

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fi69Author Commented:
Thanks CodeCruiser

I had a look at the second link you sent. Do you know what I need to do to get this to run, as I get an error "user-defined type not defined" on the Dim ref as Reference line???

Sub ReferenceProperties()
    Dim ref As Reference

    ' Enumerate through References collection.
    For Each ref In References
        ' Check IsBroken property.
        If ref.IsBroken = False Then
            Debug.Print "Name: ", ref.Name
            Debug.Print "FullPath: ", ref.FullPath
            Debug.Print "Version: ", ref.Major & "." & ref.Minor
        Else
            Debug.Print "GUIDs of broken references:"
            Debug.Print ref.GUID
        EndIf
    Next ref
End Sub

Open in new window

CodeCruiserCommented:
Where did you get that code?
Fi69Author Commented:
Hi CodeCruiser
I got it from here:
http://msdn.microsoft.com/en-us/library/aa159961(v=office.10).aspx

Reason: I was looking for more information to see if I could find a way to find out what the number in the brackets would be, eg below
References.AddFromGuid "{420B2830-E718-11CF-893D-00A0C9054228}", 1, 0

Then I found this article http://support.microsoft.com/kb/308340 which mentions
you have to add a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 library.  I think that's the reason I was getting the error.

I'm really unsure of what I'm doing, ie not sure what number in brackets to add, not sure where I shoudl be putting the code for replacing lost reference (eg on open of document, on initialisation of form containing the control, etc) so if you can assist, I'd greatly appreciate it!
CodeCruiserCommented:
The number can be found in registry. You would need to search with the name of component.
Fi69Author Commented:
The answer's there, but I lack the skill at this end to apply it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.