none
Getting a Word Control value in VB RRS feed

  • Question

  • I have a Word document with 20 Option Buttons.  The names of those option Buttons are held in a DataTable.  Can some help me with the code I need to test for the True/False state of each Option Button?

    The Name of each Option Button is held as a String in the DataTable however:

    oDoc.DataTable.Row(i).Item("ButtonName").Value does not work...

    I am trying to test the status of each Option Button from within a loop rather test each Button individually.

    Thanks for any help

    Brad


    BHend
    • Moved by Mike Feng Monday, May 30, 2011 3:13 AM Word (From:Visual Basic Express Edition)
    Thursday, May 26, 2011 10:59 PM

Answers

  • Hi BHend,

    Here is the VBA code to get the value of the ActiveX control, you can convert it to C#:

    Sub Macro1()

    Dim s As InlineShape
    Dim shapes As InlineShapes
    Set shapes = ActiveDocument.InlineShapes

    For Each s In shapes
        Set re = s.OLEFormat.Object
        Debug.Print re.Value
        Debug.Print re.Name
    Next s

    End Sub

    Hope this can give you the hint.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by BHend Wednesday, June 1, 2011 12:40 AM
    Tuesday, May 31, 2011 8:20 AM

All replies

  • That depends how you have stored your buttons.

    Now it looks if you have a database table which only contains those buttons and for every button is in a seperated row

    But also that you have used the wizard to create datatables and still use somewhere in the middle a non strongly typed dataset way..

    Very unclear.

     


    Success
    Cor
    Friday, May 27, 2011 6:01 AM
  • Cor,

    The Datatable has four columns: Name, Option1 string, Option2 String and OptionButton Name.  My intention is for each Optionbutton in the document set to true I will apply Option1 String and Option2 string if set to false.  To do this I need to be able to identify which optionButton I am dealing with in the document.  I can do it by using:

    oDoc.obItem1.Value for each of the 20 Option Buttons, but thought it would be neater and easier if I could put this test in a loop ie

    Dim lblField as Word.Field = Nothing

    For Each lblField in oDoc.Fields

        If lblField.OLE.ClassType = "Forms.optionButton.1" Then

            '  Get the OptionButton Name and extract the relevant String from the Ddatatable

       End If

    Next

    There is sure there is a better way to do this but I have found it difficult to search for

    Thanks

    Brad


    BHend
    Friday, May 27, 2011 6:42 AM
  • Hi Bhend,

    Welcome to the MSDN Forum.

    I have moved this thread to the appreciate forum.

    Thank you for your understanding and support.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 30, 2011 3:12 AM
  • Hi BHend

    Could you please describe precisely how you created these option buttons on the Word document? How to address them depends very much on the technology on which they base...

    Also, which version of Word are we dealing with?


    Cindy Meister, VSTO/Word MVP
    Monday, May 30, 2011 7:27 AM
    Moderator
  • Hello Cindy,

    I created the option buttons using the activeX toolbar from within Word 2007. 

    Thanks

    Brad


    BHend
    Monday, May 30, 2011 11:41 PM
  • Hi BHend,

    Here is the VBA code to get the value of the ActiveX control, you can convert it to C#:

    Sub Macro1()

    Dim s As InlineShape
    Dim shapes As InlineShapes
    Set shapes = ActiveDocument.InlineShapes

    For Each s In shapes
        Set re = s.OLEFormat.Object
        Debug.Print re.Value
        Debug.Print re.Name
    Next s

    End Sub

    Hope this can give you the hint.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by BHend Wednesday, June 1, 2011 12:40 AM
    Tuesday, May 31, 2011 8:20 AM
  • Heloo Bruce,

    Thank you for your assistance.  I am using VB Express 2010 and used OLEFormat.Object.Name and this has given me the string value of the name.  I forgot that just because the IDE intellisense didn't offer "Name" as an option doesn't necessarily mean it won't work.

     

    Thanks Again

    Brad


    BHend
    Wednesday, June 1, 2011 12:43 AM