Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Kent, England
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cycling controls in a document (Office 2003)

    Can anyone help? I have placed controls within a document, using the Control Toolbox (as you may have gathered from my previous post !!). I am able to name the control using "Properties" but the control name does not seem to be recognised from the VB environment. I have used the "Shapes" collection but am finding that the name appears as "Control 1" etc. Has anyone experienced this or can shed any light.

    Many thanks as always
    Jack

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Cycling controls in a document (Office 2003)

    You can refer to the controls as properties of the document:

    strText = ThisDocument.TextBox1.Text

    and you can loop through the InlineShapes collection and check the type. If you have a control, you can inspect its OLEFormat.

    Dim sh As InlineShape
    For Each sh In ThisDocument.InlineShapes
    If sh.Type = wdInlineShapeOLEControlObject Then
    Debug.Print sh.OLEFormat.Object.Name
    End If
    Next sh

  3. #3
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Kent, England
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cycling controls in a document (Office 2003)

    Thanks Hans .... still having problems though (nightmare !!). The code you supplied cycled through and gave me the name of each control (cmdANService1, cmdANService2, cmdANService3, cmdANService4, cmdANServiceFinal). I then changed the code to run a function using the control.

    Private Sub UserForm_Initialize()
    Dim shpShape As Shape

    For Each shpShape In ThisDocument.Shapes
    If shpShape.Type = msoOLEControlObject Then
    PopulateComboBox shpShape.OLEFormat.Object
    End If
    Next shpShape

    End Sub

    This tripped instantly and the code stopped - I am unsure why. If I physically type the command button name after the PopulateComboBox function it works fine (PopulateComboBox cmdANService1) but realistically I would end up with quite a few lines as I have 20 command buttons and I feel this is not the most efficient way to populate the combo box.

    Any help would be greatly appreciated.

    Regards
    Jack

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Cycling controls in a document (Office 2003)

    What is the code (or at least the first line) for PopulateComboBox?

  5. #5
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Kent, England
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cycling controls in a document (Office 2003)

    Here's the code ....

    Public Sub PopulateComboBox(pcntControl As Control)

    With pcntControl
    .AddItem "E"
    .AddItem "ET"
    .AddItem "OT"
    .AddItem "AT"
    .AddItem "U"
    End With

    End Sub

    This is being populated in a userform when a user clicks on the control

    Regards
    Jack

  6. #6
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Kent, England
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cycling controls in a document (Office 2003)

    Hans .... apologies, I think I had become confused with the userform and controls. All has been resolved now.

    Many thanks for your help as always
    Jack

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Cycling controls in a document (Office 2003)

    I'm sorry, I don't understand. In your previous reply, you told us that you have a series of command buttons in your document. You cannot add items to a command button, only to a list box or combo box. Or do I misinterpret your reply?

Posting Permissions

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