none
C#_&_Excel_Form_Controls__Possible?_Yes/No_How? RRS feed

  • Question

  • Hi,There are some ways to read data from excel_ActiveXControls :

    //Get a specific data from activeX control

    using Excel=Microsoft.Office.Interop.Excel ;

    Excel.Shape excelShape = xlWorkSheet.Shapes.Item("excel_activeX_TextBox1");

     Excel.OLEObject excelOleObject = (Excel.OLEObject)excelShape.OLEFormat.Object;

     csharp_txt.Text = excelOleObject.Object.GetType().InvokeMember("Text", System.Reflection.BindingFlags.GetProperty, null, excelOleObject.Object, null).ToString();

    //or even better get a whole excel activeXcontrol

    using MSForm = Microsoft.Vbe.Interop.Forms;

    Excel.OLEObject cbOLEObj = (Excel.OLEObject)xlWorkSheet.OLEObjects("excel_ActiveX_TextBox4");

    MSForm.TextBox txtBox = (MSForm.TextBox)cbOLEObj.Object;//txtBox is your excel activeX textbox but in C#

    csharp_textBox1.Text = txtBox.Text;

     

     

    But I do have next problem.How to read data from Excel UserForm's.So I have some textboxes(form Controls) on userform and I wanna get their data in my c# application.Is this possible at all,if yes how?, can someone show it?.

    Why do I need this?I have activeXControls on my xlwoorksheet,but since I can't find ActiveXControl Panel or some activeX form(so I have background for some of my activeXControls),I need to use FormControls.

    I do have two options:

    1.To find activeX panel or 2.find out how to read data from form controls in userform.

    So is there Panel(in excel 2010) as activeXcontrol so I can put in 3-4 activeX textboxes??(I couldnt find it).

    I am using office 2010

     




    Friday, April 8, 2011 11:03 PM

Answers

  • Hi Soble

    I'm having some difficulty understanding the entirety of what you want to do. But since you posted this question in the VSTO forum I would have to assume you're using VSTO. If you aren't, then your question is off-topic here and would belong in the Excel Developer forum.

    If you are using VSTO then you should be using WinForms controls, hosted on the Excel sheet, not ActiveX controls. For these, you can create a custom User Control, which sounds like it's exactly what you want...

    As far as I know, there's no way for your VB.NET code to directly access the content of controls on a loaded and running UserForm. But since you apparently want to use parts of VBA anyway, why not have VBA code extract the information? You can run VBA code from your VB.NET solution...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Soble Saturday, April 9, 2011 11:37 AM
    Saturday, April 9, 2011 10:20 AM
    Moderator

All replies

  • Hi Soble

    I'm having some difficulty understanding the entirety of what you want to do. But since you posted this question in the VSTO forum I would have to assume you're using VSTO. If you aren't, then your question is off-topic here and would belong in the Excel Developer forum.

    If you are using VSTO then you should be using WinForms controls, hosted on the Excel sheet, not ActiveX controls. For these, you can create a custom User Control, which sounds like it's exactly what you want...

    As far as I know, there's no way for your VB.NET code to directly access the content of controls on a loaded and running UserForm. But since you apparently want to use parts of VBA anyway, why not have VBA code extract the information? You can run VBA code from your VB.NET solution...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Soble Saturday, April 9, 2011 11:37 AM
    Saturday, April 9, 2011 10:20 AM
    Moderator
  • Hi Cindy,My english isnt the best so I will try explain on this way:

    I want to read data from FormControls(they are placed on Excel UserForms)

    So one UserForm(called UserForm1) with one textbox(called Textbox1)(FormControl) in my excel file,containing value let's say Textbox.text="Good Morning"

    is there any way I can get this value("Good Morning") directly  from This Textbox(textbox is placed in excel userform) in my c# program. 

    I only need this cuz I dont want to put my controls(activeXcontrols) in excel sheet without some backgound,So I need panel to put ActiveXControls on it,but  I couldnt find panel as activeXControl,so I switch to Custom UserForm with FormControls(There i have Form as a background,but I dont know how to read their data from c#).

    .............................

     

    Since I am able  to read data from activeX Controls, is there any ActivexControl  like panel,so I can put few ActiveXControls on it???When I click Developer->Insert->More Controls-> I get a list of controls but there is no panel inside list.???


    Saturday, April 9, 2011 10:43 AM
  • Hi Soble

    As I explained in my previous message, I don't think you can do what you want to do. I offered you a different approach in my previous message.

    In any case, you definitely need to provide more information about the software versions involved in your scenario...


    Cindy Meister, VSTO/Word MVP
    Saturday, April 9, 2011 11:21 AM
    Moderator
  • Hi Soble

    As I explained in my previous message, I don't think you can do what you want to do. I offered you a different approach in my previous message.

    In any case, you definitely need to provide more information about the software versions involved in your scenario...


    Cindy Meister, VSTO/Word MVP

    Ok,That's clear now,ty:P. Btw I am using Excel 2010 and Visual Studio 2008. My project type is Windows Forms Application.

    About your approach:

    Do you think about using excel application.run method?( Microsoft.Office.Interop.Excel.Application.Run() )? (To run VBA macros).I tryed this but couldnt find out how this method works,It has 32 parameters.

    Thx on patience!




    Saturday, April 9, 2011 11:34 AM
  • I have just tryed again excel.application run method().It works,but Where can I find description about parameters of this method.
    Saturday, April 9, 2011 12:55 PM