locked
Word 2010 VBA create radio button RRS feed

  • Question

  • Hi,
    How can you create radio buttons in word 2010 with VBA code and Assign them their properties (name, group ...) ?
    Thank You !

    Wednesday, August 28, 2013 1:13 PM

Answers

  • Hi,

    I record macro when I insert option button to document and find the method below:

    Selection.InlineShapes.AddOLEControl ClassType:="Forms.OptionButton.1"

    Then I change it a little for your reference:

    Set optionBtn1 = Application.ActiveDocument.InlineShapes.AddOLEControl(ClassType:="Forms.OptionButton.1")
    
         optionBtn1.OLEFormat.Object.GroupName = "sex"
    
         optionBtn1.OLEFormat.Object.Caption = "male"
    
         optionBtn1.OLEFormat.Object.Name = "sex_ male"
    
         optionBtn1.OLEFormat.Object.Value = False
    
         
         Set optionBtn2 = Application.ActiveDocument.InlineShapes.AddOLEControl(ClassType:="Forms.OptionButton.1")
    
         optionBtn2.OLEFormat.Object.GroupName = "sex"
    
         optionBtn2.OLEFormat.Object.Caption = "female"
    
         optionBtn2.OLEFormat.Object.Name = "sex_female"
    
        optionBtn2.OLEFormat.Object.Value = True
    

    You can get more information from link below:

    Shapes.AddOLEControl Method (Word)

    ContentControls.Add Method (Word)

    • Marked as answer by George Hua Tuesday, September 3, 2013 1:31 PM
    Thursday, August 29, 2013 11:32 AM

All replies

  • Hi Jean,

    Thank you for visiting the MSDN forum.

    I’m afraid that it is not the correct forum about this issue, since this forum is to discuss Visual

    Basic. I moved this thread to Word for developers Forum for more efficient responses

    #Word for developers Forum

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=worddev 

    Thanks for your understanding.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, August 29, 2013 2:10 AM
  • Hi,

    I record macro when I insert option button to document and find the method below:

    Selection.InlineShapes.AddOLEControl ClassType:="Forms.OptionButton.1"

    Then I change it a little for your reference:

    Set optionBtn1 = Application.ActiveDocument.InlineShapes.AddOLEControl(ClassType:="Forms.OptionButton.1")
    
         optionBtn1.OLEFormat.Object.GroupName = "sex"
    
         optionBtn1.OLEFormat.Object.Caption = "male"
    
         optionBtn1.OLEFormat.Object.Name = "sex_ male"
    
         optionBtn1.OLEFormat.Object.Value = False
    
         
         Set optionBtn2 = Application.ActiveDocument.InlineShapes.AddOLEControl(ClassType:="Forms.OptionButton.1")
    
         optionBtn2.OLEFormat.Object.GroupName = "sex"
    
         optionBtn2.OLEFormat.Object.Caption = "female"
    
         optionBtn2.OLEFormat.Object.Name = "sex_female"
    
        optionBtn2.OLEFormat.Object.Value = True
    

    You can get more information from link below:

    Shapes.AddOLEControl Method (Word)

    ContentControls.Add Method (Word)

    • Marked as answer by George Hua Tuesday, September 3, 2013 1:31 PM
    Thursday, August 29, 2013 11:32 AM
  • Thank You!
    Friday, September 20, 2013 2:33 PM
  • Thank you.

    It was very helpfull !

    Friday, September 20, 2013 2:34 PM