Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove/Install Reference

Posted on 2012-04-04
9
Medium Priority
?
526 Views
Last Modified: 2012-04-30
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?
0
Comment
Question by:Fi69
  • 5
  • 3
9 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37806862
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?
0
 

Author Comment

by:Fi69
ID: 37806940
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????
0
 

Author Comment

by:Fi69
ID: 37806944
Sorry, the steps above, obviously I changed it to the MSCOMCT2 control rather than the MSCOMCTL that they mention.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1000 total points
ID: 37807508
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
0
 

Author Comment

by:Fi69
ID: 37808824
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

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37810475
Where did you get that code?
0
 

Author Comment

by:Fi69
ID: 37811331
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!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37811958
The number can be found in registry. You would need to search with the name of component.
0
 

Author Closing Comment

by:Fi69
ID: 37910188
The answer's there, but I lack the skill at this end to apply it.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question