Bargholz Thomas
Posts: 243
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
|
|
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. |
|
Andrei Smolin
Add-in Express team
Posts: 19138
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 |
|
Bargholz Thomas
Posts: 243
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 :-) |
|