Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2008
    Fort Knox

    Unanswered: Reference ActiveX field in MS word by string or index

    Sorry but I wasn't sure where else to put this, although this will be part of an Access application that I'm making ... using forms designed in MS Word.

    I'm trying to reference an ActiveX field in MS Word by a "string" value. Most of the ActiveX fields in this form are named "B1", "B2", "B3", etc. So I could easily do something like this:

    ThisDocument.Controls("B1") = "value"
    ... except that there is no "Controls" member.

    I've done a bit of Google-ing and I've found that this is supposed to work:

    Reference: vba - Use a variable to select an ActiveX control Checkbox by name (in Word from Excel)? - Stack Overflow

    But every time I reference Me.InlineShapes.Count ... I get zero.

    Is there a way to do this in Word? Or am I totally hosed? If I could at least use an index like the reference suggests, then I'd be ok. I could write a function to loop through and return the proper index, but I can't even get that at this rate...

    I have a few contingencies but they are less than ideal.

    Any insight would be appreciated!

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 15
    Refer to the Microsoft Word Object Model (Word Object Model Reference) to know the available references you can use.
    Have a nice day!

  3. #3
    Join Date
    Feb 2008
    Fort Knox
    Sorry for asking such a simple question. Here's what I came up with in case anyone looks for this one:

    InField is the name given to the ActiveX control within the document.

    Public Function GetFieldIndex(InField As String)
        Dim TotShapes As Long, i As Long, ObjName As String, _
            ShapeName As String, ShapeType As String
        i = 1
        TotShapes = ThisDocument.Shapes.Count
        Do While i <= TotShapes
            ShapeName = ThisDocument.Shapes(i).Name
            If ShapeName Like "Control *" Then
                ObjName = ThisDocument.Shapes(i).OLEFormat.Object.Name
                Else: GoTo NextObj
            End If
            If ObjName = InField Then
                GetFieldIndex = i
                GoTo EndFunc
            End If
            i = i + 1
    End Function
    For anyone confused like I was because of the post on stackoverflow, it turns out the InlineShapes member is supposed to cover ActiveX objects. However there is no name property so the above code idea won't work. I'm sure there's a way to parse for the index ID of a given ActiveX control using InlineShapes , but I used the Shape member instead and that also provided a way to filter out all other shapes except ActiveX text boxes, combo boxes, list boxes, buttons, etc..., thus avoiding errors.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts