Word Add-in pane not appearing

May 15, 2014 at 4:50 PM
I’m new to NetOffice. Very cool product! I appreciate the hard work.

My MS Word add-in pane was appearing until I clicked the Close X button on the add-in. Now it won't appear. However, when I launch MS Word via NetOffice.DeveloperToolbox's OfficeUI feature, my add-in pane is visible.

I have a MS Word menu button and that button toggles the Visible state of the pane. That button works when Word is launched via NetOffice.DeveloperToolbox. But it doesn't show the pane when Word is launched normally.

When I launch MS Word, a document opens automatically. It's that same document that was open when my pane was visible and I clicked the Close/X button. I've added break points to my add-in's AddIn class and it is indeed being created when MS Word starts.

Maybe MS Word saves the add-in's Visible in the document. Or perhaps in a registry key. Or even in a file. But even so, why doesn't setting Visible=true show the pane?
  • Windows 7 x64
  • Office 2010 Home & Student x64
  • NetOffice 1.6.0
  • When I created the add-in via the wizard, I choose Current User.
namespace FcptWordEmrTaskPaneAddIn {
    [COMAddin("FcptWord", "First Choice PT MS Word EMR Add-In", 3)]
    [GuidAttribute("2A47524B-E1A2-4F32-9826-864EE9DFA740"), ProgId("FcptWord.TaskPaneAddin")]
    public class Addin : COMAddin {
        public Addin() {
            this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);
            this.OnConnection += new OnConnectionEventHandler(Addin_OnConnection);
            this.OnDisconnection += new OnDisconnectionEventHandler(Addin_OnDisconnection);

            var app = Word.Application.GetActiveInstance();
            
            string title = "EMR Task Pane";
            TaskPanes.Add(typeof(AddInUI), title);
            foreach (var tp in TaskPanes) {
                if (tp.Title == title) {
                    tp.DockPosition = MsoCTPDockPosition.msoCTPDockPositionLeft;
                    tp.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
                    tp.Width = 150;
                    tp.Visible = true;
                    tp.Arguments = new object[] { this };
                    var cc = app.CustomizationContext;
                }
            }
        }

        void Addin_OnConnection(object Application, NetOffice.Tools.ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { }

        void Addin_OnStartupComplete(ref Array custom) {
            CreateUserInterface();
        }

        void Addin_OnDisconnection(NetOffice.Tools.ext_DisconnectMode RemoveMode, ref Array custom) {
            RemoveUserInterface();
        }

        void CreateUserInterface() {
            var app = Word.Application.GetActiveInstance();
            CommandBar fileMnuBar = app.CommandBars["File"];
            fileMnuBar.Reset();
            var OptionsButton = (CommandBarButton)fileMnuBar.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, fileMnuBar.Position + 3, true);
            OptionsButton.Tag = "cxrnd1024";
            OptionsButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
            OptionsButton.Caption = "EMR";
            OptionsButton.ClickEvent += new CommandBarButton_ClickEventHandler(FcptEmr_ClickEvent);
        }

        void FcptEmr_ClickEvent(CommandBarButton Ctrl, ref bool CancelDefault) {
            foreach (var tp in TaskPanes) {
                try {
                    tp.Visible = !tp.Visible;
                } catch (Exception) { }
            }
        }

        void RemoveUserInterface() { }
    }
}
Coordinator
May 16, 2014 at 8:49 PM
okay... this means the pane is visible at first MS-Word start and never again? (it looks like for an unhandled exception)
if its possible, please send me your solution to public[at]sebastian.web.de(remove private code, i dont need this to clearify the situation)

BTW: i suggest you to avoid 'GetActiveInstance()' this method gives you the first instance in memory but not sure its your's. (may multiple word instances currently working)

Better idea:

Keep the application in a private field:

private NetOffice.WordApi.Application _app;

void Addin_OnConnection(object Application, NetOffice.Tools.ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
{
_app = new NetOffice.WordApi.Application(null, Application);
}

void Addin_OnDisconnection(NetOffice.Tools.ext_DisconnectMode RemoveMode, ref Array custom)
{
RemoveUserInterface();
 _app.Dispose();
}

(Nice to know: NO 1.7 makes this easier with the NO Tools, the application is available here as addin instance property)

*Sebastian
May 20, 2014 at 1:05 PM
I got it working. Thank you for the suggestions. Your assistance is appreciated. Thanks for GetActiveInstance() tip too!

Greg