none
How to get value from active-x Textbox control in Word RRS feed

  • Question

  • Create active-x Textbox control in Word. Enter some text in it like "box1box". Then using OpenXml Tool to open file and reflect code. You will not able to see the text string since they are images. Something like these:

       <w:object w:dxaOrig="1440" w:dyaOrig="1440">
          <v:shapetype id="_x0000_t75" coordsize="21600,21600" filled="f" stroked="f" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml">
            <v:stroke joinstyle="miter" />
            <v:formulas>
              <v:f eqn="if lineDrawn pixelLineWidth 0" />
              <v:f eqn="sum @0 1 0" />
              <v:f eqn="sum 0 0 @1" />
              <v:f eqn="prod @2 1 2" />
              <v:f eqn="prod @3 21600 pixelWidth" />
              <v:f eqn="prod @3 21600 pixelHeight" />
              <v:f eqn="sum @0 0 1" />
              <v:f eqn="prod @6 1 2" />
              <v:f eqn="prod @7 21600 pixelWidth" />
              <v:f eqn="sum @8 21600 0" />
              <v:f eqn="prod @7 21600 pixelHeight" />
              <v:f eqn="sum @10 21600 0" />
            </v:formulas>
            <v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f" />
            <o:lock v:ext="edit" aspectratio="t" />
          </v:shapetype>
          <v:shape id="_x0000_i1031" style="width:220.65pt;height:18pt" alt="altbox1" o:ole="" type="#_x0000_t75" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml">
            <v:imagedata o:title="" r:id="rId5" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
          </v:shape>
          <w:control w:name="TextBox1" w:shapeid="_x0000_i1031" r:id="rId6" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
        </w:object>

    • Moved by Fred Bao Monday, September 15, 2014 6:49 AM
    Friday, September 12, 2014 4:18 PM

Answers

  • Hi YiJun,

    As far as I know, we can't use Open XML to read value from activeX control. As a workaround, I suggest that you use Word Object model.

    And here is the code use Word Object model read textBox for your reference:

      public static void Main()
            {
    
                Word.Application wordApp = new Word.Application();
    
                Word.Document doc = wordApp.Documents.Open(@"fullPath");
    
                foreach (InlineShape shape in doc.InlineShapes)
                {
    
                
                    if (shape.OLEFormat != null && shape.OLEFormat.ClassType == "Forms.TextBox.1" && shape.OLEFormat.Object.Name == "TextBox1")
                    {
    
                        Console.WriteLine("{0}'s value is {1}", shape.OLEFormat.Object.Name, shape.OLEFormat.Object.Value);
                        Console.ReadLine();
                    }
    
                }
    
                doc.Close();
    
                wordApp.Quit();
    
            }

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, September 15, 2014 7:09 AM
    Moderator

All replies

  • Hello Yijun Ding,

    Since your issue is related with OpenXML, I move this thread to the OpenXML for getting better help.

    Thanks for your undertsanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 15, 2014 6:48 AM
  • Hi YiJun,

    As far as I know, we can't use Open XML to read value from activeX control. As a workaround, I suggest that you use Word Object model.

    And here is the code use Word Object model read textBox for your reference:

      public static void Main()
            {
    
                Word.Application wordApp = new Word.Application();
    
                Word.Document doc = wordApp.Documents.Open(@"fullPath");
    
                foreach (InlineShape shape in doc.InlineShapes)
                {
    
                
                    if (shape.OLEFormat != null && shape.OLEFormat.ClassType == "Forms.TextBox.1" && shape.OLEFormat.Object.Name == "TextBox1")
                    {
    
                        Console.WriteLine("{0}'s value is {1}", shape.OLEFormat.Object.Name, shape.OLEFormat.Object.Value);
                        Console.ReadLine();
                    }
    
                }
    
                doc.Close();
    
                wordApp.Quit();
    
            }

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, September 15, 2014 7:09 AM
    Moderator
  • I think you're correct, there is no text. MS Word stores the content of that ActiveX control as windows metafile.

    One option will be to search the web on Metafile file format, to extract the text.

    I don't know is this the option for your company, but I would use newer type of controls, content controls.

    Regards,

    Michael

    Monday, September 15, 2014 5:00 PM