Ask a questionAsk a question
 

AnswerMS Word Option Button Collection

  • Sunday, October 23, 2005 3:42 PMNess22 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I am trying to use option buttons from the control toolbox in a word document.
    I have set the groupname and they work fine but....
    I then need to loop through the option button values in the group and I can not work out how to create the array or collection - I have tried the shapes property and the inlineshapes property of the active document but they have not worked.
    I need code a bit alike below:

    dim optBtn as msforms.optionbutton
    for each optbtn in activedocument.??

    msgbox optBtn.value

    next optBtn

    I can not work out what should be where the ?? are

    Please help

    Many thanks

Answers

  • Friday, October 28, 2005 4:47 PMMS ISV Buddy Team Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Per one of our support engineers... try this code:

    ======

    Dim optBtn As Control
     

    For Each optBtn In Me.Controls
     

    If TypeName(optBtn) = "OptionButton" Then

        If optBtn.GroupName = "test" Then
     

            MsgBox optBtn.Value
      

        End If

    End If

    Next optBtn

    ======

    I hope this helps,
    -brenda (ISV Buddy Team)

  • Monday, November 07, 2005 9:11 PMMicHerz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The code in the first response only works if the controls are on a userform. In your case, the controls are directly on the document. Assuming your controls are all in the main document (as opposed to in headers/footers, footnotes/endnotest, or textboxes), and assuming they are all inline and not floating, then the following code should work:

        Dim oShape As Word.InlineShape
       
        For Each oShape In ActiveDocument.InlineShapes
            If oShape.OLEFormat.ProgID = "Forms.OptionButton.1" Then
                MsgBox oShape.OLEFormat.Object.Value
            End If
        Next

    Michael Herzfeld
    Office Programmability Test Team

All Replies

  • Friday, October 28, 2005 4:47 PMMS ISV Buddy Team Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Per one of our support engineers... try this code:

    ======

    Dim optBtn As Control
     

    For Each optBtn In Me.Controls
     

    If TypeName(optBtn) = "OptionButton" Then

        If optBtn.GroupName = "test" Then
     

            MsgBox optBtn.Value
      

        End If

    End If

    Next optBtn

    ======

    I hope this helps,
    -brenda (ISV Buddy Team)

  • Monday, November 07, 2005 9:11 PMMicHerz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    The code in the first response only works if the controls are on a userform. In your case, the controls are directly on the document. Assuming your controls are all in the main document (as opposed to in headers/footers, footnotes/endnotest, or textboxes), and assuming they are all inline and not floating, then the following code should work:

        Dim oShape As Word.InlineShape
       
        For Each oShape In ActiveDocument.InlineShapes
            If oShape.OLEFormat.ProgID = "Forms.OptionButton.1" Then
                MsgBox oShape.OLEFormat.Object.Value
            End If
        Next

    Michael Herzfeld
    Office Programmability Test Team
  • Thursday, November 13, 2008 2:40 PMSenshan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi

     

    I usethe folloing code get all the inline shapes

     

    Microsoft.Office.Interop.Word.InlineShapes shapes;

    shapes = (Microsoft.Office.Interop.Word.InlineShapes)doc.GetType().InvokeMember("InlineShapes", BindingFlags.GetProperty, null, doc, null);

     

    But it is not retriving inline shapes in footnotes/endnotest, or textboxes. Is there a way to retrive the inlineshapes in the footnote . textbox.

     

    Is there any specifice reason for this is not retriving the inlineshapes in the footnote and Textbox

     

    Thanx

    -Senthil 

  • Tuesday, November 03, 2009 10:04 PMJesús Edmundo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You have to go through each footnote and look inside the range...

      foreach (Footnote fn in Application.ActiveDocument.Footnotes)
                {
                    foreach (InlineShape shape in fn.Range.InlineShapes)
                    {
                        // here your code using the shape obj.
                    }
                }