Solved

Remove/Install Reference

Posted on 2012-04-04
9
515 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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now