Add-in loaded and commandbar visible...

Add-in Express™ Support Service
That's what is more important than anything else

Add-in loaded and commandbar visible...
but the add-ins commandbars can't be listed using automation 
Bargholz Thomas




Posts: 242
Joined: 2006-12-18
I have some C# code which runs through visible command bars. It finds all the standard Word commandbars, but not the ones added by my Add-in-express based add-in. How do I programatically check if the commandbars are visible?

The add-in is loaded and the commandbars are visible and functioning, so I expected them to show up in the commandbars collection of Word.

It's Office 2003 and Add-in Express 4.4.1912.

Here is the C# code I'm using to check for the commandbar:

using Office = Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;
// ...
Word.ApplicationClass wordClass = new Word.ApplicationClass();
Office.CommandBar commandBar;
for(int i = 1; i < wordClass.CommandBars.Count + 1; i++)
{
commandBar = wordClass.CommandBars[i];
if (commandBar.Visible)
{
Console.WriteLine(" - " + commandBar.Name);
}
}

Regards
Thomas


Posted 19 Jan, 2009 08:22:09 Top
Eugene Astafiev


Guest


Hello Bargholz,

I have reproduced the issue you described above. It seems that you set the Temporary property of the command bar. You can set the Temporary property of the command bar to false and see your command bar in the list of command bars.
Posted 19 Jan, 2009 15:34:40 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Bargholz,

The following code produces "OK" for me:

Office.CommandBar cmb = null;
try
{
    cmb = WordApp.ActiveDocument.CommandBars["adxCommandBar1"];
    System.Windows.Forms.MessageBox.Show("OK");
}
catch
{
    System.Windows.Forms.MessageBox.Show("error");
}



Andrei Smolin
Add-in Express Team Leader
Posted 19 Jan, 2009 15:48:21 Top
Bargholz Thomas




Posts: 242
Joined: 2006-12-18
I also discovered, that if I opened Word first, so that my commandbar was visible, then my code worked.
But automating Word without opening it first didn't find it when asking the Application.CommandBars.
So it appears that using ActiveDocument.CommandBars forced Word to load the addin, so I could find it.

Thanks for the help :-)
Posted 21 Jan, 2009 09:06:33 Top
Eugene Astafiev


Guest



You are welcome, Thomas.
Posted 21 Jan, 2009 09:08:58 Top