none
Insert activex user control using c# in word issue RRS feed

  • Question

  • I created on activex user control using c#. Then I built it to dll file and regasm this dll to system

    This user control just simple example has one button and source code this file like it:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    namespace ActiveXTest
    {
        [ProgId("DemoTestUserControl")]
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [Guid("415D09B9-3C9F-43F4-BB5C-C056263EF278")]
        [ComVisible(true)]
        public partial class DemoTestUserControl : UserControl
        {
            private string myParam = "Empty";

            public DemoTestUserControl()
            {
                InitializeComponent();
            }

            /// <summary>
            /// Parameter visible from JS
            /// </summary>
            [ComVisible(true)]
            public string MyParam
            {
                get
                {
                    return myParam;
                }
                set
                {
                    myParam = value;
                }
            }

            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show(MyParam);
            }
        }
    }


    I created one marco function to insert this control to office word like as:

    Public Sub DPWPTextReferencePaste()

       Const TEXT_REFERENCE_CLASS As String = "DemoTestUserControl"

       Dim ishInlineShape            As InlineShape

       ' Create the text reference object
       Set ishInlineShape = ActiveDocument. _
                            InlineShapes. _
                            AddOLEObject( _
                               ClassType:=TEXT_REFERENCE_CLASS, _
                               DisplayAsIcon:=False, _
                               Range:=Selection.Range)

    When I call this function it already insert the control to word
    But after saving and opening it again the control doesn't show it in correctly. I can't see this button and click it. Just see red cross image in word



    Somebody can help me this issue. How can I save it and open it again like insert button time

                                                                                 
    Saturday, December 10, 2016 9:49 AM

All replies

  • Hi Tuan Kieu,

    From the description of thread it's looks like after creating the dll file.

    you add the reference in VBE.

    so that you are able to use the functionality of that class.

    then when you close and reopen the file at that time the reference get broke and because of that you are not able to view the button.

    do you get any error? if so then let us know about that.

    also try to link to file option true and check whether it work or not.

    LinkToFile:=True

    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.

    Monday, December 12, 2016 2:41 AM
    Moderator