none
How to use option button (activeX) on Excel Sheet with VSTO C# RRS feed

  • Question

  • Hi Expert,

    Can you please suggest me how to get value of a option button placed on sheet?

    I am automating one excel application using VSTO. Excel sheet have 5 option button. I need to read value of options button.

    what is the code to do it.

    Regards,

    Divaker

    Tuesday, January 17, 2017 1:14 PM

All replies

  • Hello Divaker,

    Microsoft.Office.Interop.Excel.OptionButton opt = (Microsoft.Office.Interop.Excel.OptionButton)currentSheet.OptionButtons(1);

    opt.Value=true; // for checked


    You can use the Value property of the OptionButton for checking whether it is selected or not.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers


    Tuesday, January 17, 2017 1:50 PM
  • Thanks for Reply

    But I am getting following error




    Tuesday, January 17, 2017 3:02 PM
  • Hi Divaker Pandey,

    Directly check the .checked property of Radio Button.

    below is the example of that.

    private void ClickMyRadioButton()
    {
       // If Item1 is selected and radioButton2 
       // is checked, click radioButton1.
       if (listBox1.Text == "Item1" && radioButton2.Checked)
       {
          radioButton1.PerformClick();
       }
    }
    

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 18, 2017 12:55 AM
    Moderator
  • Hi Deepak,

    Thanks.

    I want to access ActiveX control available on excel sheet through C#.

    Have you any idea how to access them.

    Regards,

    Wednesday, January 18, 2017 1:26 PM
  • Hi Divaker Pandey,

    you can refer the code mentioned below.

     Excel.Application excelApp = new Excel.Application();
                excelApp.Visible = true;
                Excel.Workbook wb = excelApp.Workbooks.Open(@"C:\Users\v-bpeng\Desktop\combobox.xlsx");
                Excel.Worksheet ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
    
                // this can get the Form controls
                foreach (Shape s in ws.Shapes)
                {
                    MessageBox.Show(s.Name);
                    Shape shp = ws.Shapes.Item(s.Name);
                }                  
    
                // this can get the ActiveX controls
                foreach (OLEObject oleobj in ws.OLEObjects())
                {
                    MessageBox.Show(oleobj.Name);
                }

    Reference:

    Refer ActiveX control using C#

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 19, 2017 5:06 AM
    Moderator