1
votes

I have a Word document originally created on a Windows 7 32-bit machine, that is now giving me problems since switching to Windows 7 64-bit. Both systems are running Word 2010 (v14.0.7173.5000, 32-bit). The Word document has many ActiveX Labels, and a large macro which links each ActiveX Label to a specific cell in an Excel document. This way I update the Excel file, and I run the Word macro to update all the labels.

Here is how the ActiveX Labels look in VBA when the Word document is opened on a Win7 x86 machine:

enter image description here

However when the document is opened on a Win7 x64 machine, the Labels are renamed with a "1" at the end:

enter image description here

Because there have been no changes to my VBA code itself, if I run the macro I get the error message "Object library invalid or contains references to object definitions that could not be found". If I try and fix the Labels by removing the "1", I get an "Ambiguous Name Detected" error message.

If I re-save the file with the extra "1" in the Label, the new Labels are retained and visible when opened on a Win7 x86 machine. That same machine is then able to remove the extra "1", but if I try to do the same on a Win7 x64 machine I get the "Ambiguous Name Detected" error message again.

Does anyone know what is causing this problem, and also how to fix it?

1
Have you tried fixing the handlers to add the 1 and then saving (a copy of) the document?Mathieu Guindon
Not yet. Is there an easy way to do that instead of selecting each label one by one from the pull down menu (like in my screenshots)?wongnog
If you can only see 1 procedure at a time in the code pane, you need to switch to "module view" (one of the toggle buttons at the bottom/corner of the code pane); you should be able to just scroll through your module without ever needing to use these dropdowns to navigate. Or get the latest Rubberduck and use the Code Explorer and other navigation tools to browse your code (note, v2.x isn't exactly fully stable yet though, but we're working on it ;-).Mathieu Guindon
My VBA code is under the Microsoft Word Object for "ThisDocument", rather than a module. Is that a problem?wongnog
Makes no difference, I'm talking about the editor itself - this toggle button (see the tooltips on these two buttons).Mathieu Guindon

1 Answers

1
votes

Seems your controls need to have their names fixed/changed. You can do this manually in design mode.

Or you can update your code so that instead of this:

ThisDocument.ai_oos_01.Caption = "whatever"

You do this:

FixControlNameAndSetCaption "ai_oos_01", "whatever"

Just grab this procedure and put it in a standard module (e.g. Module1):

Public Sub FixControlNameAndSetCaption(ByVal controlName As String, ByVal newCaption As String)
    Dim wordShape As InlineShape
    For Each wordShape In ThisDocument.InlineShapes
        With wordShape.OLEFormat.Object
            If Left$(.Name, Len(controlName)) = controlName Then
                If .Name <> controlName Then .Name = controlName
                .Caption = newCaption
                Exit Sub
            End If
        End With
    Next
End Sub

Now, if the controls' .Name matches the specified controlName exactly, only the .Caption will change (which is what your code is currently supposed to be doing). If the controls' .Name would match the specified controlName if that pesky numeric suffix wasn't there, then it renames the control to the specified controlName, which effectively "cures" your control names.

HOWEVER, if you have legit/expected control names Foobar01 and Foobar012, then I don't have a solution other than to strongly recommend you avoid numeric suffixes when naming things, and give things meaningful/descriptive names, always.

The implication of not referring to ThisDocument.ai_oos_01 directly, is that your code still compiles and runs if the objects somehow get renamed again (I suspect document corruption, or someone duplicated all the controls and/or deleted the original ones, perhaps by accident).