kcthota

Hi,
I have written a word add-in which consists of a command bar button. My add-in is available if I launch Word 2007 program. However, if I open an existing document the add-in is unavailable.

Please let me know what should be done for my add-in to be available while opening an existing document also.

Thanks




Re: Visual Studio Tools for Office Word Add-in not available while opening documents

belote

I think you must use another event.

in place of "(youraddin Events)" in the dropdown list

select "Application"

After that, in the right, select the event you want (I think you want the "DocumentOpen" event)





Re: Visual Studio Tools for Office Word Add-in not available while opening documents

kcthota

Hey belote,

I could not find any such event (DocumentOpen). Can you please give me some sample code, which would call my add-in while any document is being opened.

Thanks






Re: Visual Studio Tools for Office Word Add-in not available while opening documents

belote

when you are in the code of your add-in, in visual studio, you have 2 dropdown list in the top.

In the left dropdown list, you must select "Application". And in the right you must have events for the application, as "DocumentOpen"

Don't you see that





Re: Visual Studio Tools for Office Word Add-in not available while opening documents

kcthota

I just have WordAddIn1.ThisAddIn in the left drop down list.

Thanks






Re: Visual Studio Tools for Office Word Add-in not available while opening documents

Cindy Meister

kcthota wrote:

I have written a word add-in which consists of a command bar button. My add-in is available if I launch Word 2007 program. However, if I open an existing document the add-in is unavailable.

Please let me know what should be done for my add-in to be available while opening an existing document also.

Please show us the code that declares the command bar button, instantiates and modifies it. Possibly you aren't doing this "just right" for the way Word needs it done in order to show the command bar objects for all document windows. But we have to see the code first...

Why are you adding a CommandBar button to Word 2007 rather than using the Ribbon interface






Re: Visual Studio Tools for Office Word Add-in not available while opening documents

kcthota

Hi Cindy,

I am not aware of the Ribbon interface; I am following the procedure to create a menu mentioned at http://msdn2.microsoft.com/en-us/library/0batekf4(VS.80).aspx

The following is the code I am using.

private Office.CommandBarButton menuCommand;

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

myaddin = new Microsoft.Office.Tools.AddIn();

CheckIfMenuBarExists();

AddMenuBar();

}

// If the menu already exists, remove it.

private void CheckIfMenuBarExists()

{

try

{

Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)

this.Application.CommandBars.ActiveMenuBar.FindControl(

Office.MsoControlType.msoControlPopup, System.Type.Missing, "My App", true, true);

if (foundMenu != null)

{

foundMenu.Delete(true);

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

}

// Create the menu, if it does not exist.

private void AddMenuBar()

{

try

{

Office.CommandBarPopup cmdBarControl = null;

Office.CommandBar menubar = (Office.CommandBar)Application.CommandBars.ActiveMenuBar;

int controlCount = menubar.Controls.Count;

// Add the menu.

cmdBarControl = (Office.CommandBarPopup)menubar.Controls.Add(

Office.MsoControlType.msoControlPopup, missing, missing, controlCount, true);

if (cmdBarControl != null)

{

cmdBarControl.Caption = "My App";

cmdBarControl.Tag = "My App";

// Add the menu command.

menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(

Office.MsoControlType.msoControlButton, missing, missing, missing, true);

menuCommand.Caption = "Show &Pane";

menuCommand.Tag = "Show Pane";

menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand_Click);

}

}

catch (Exception e)

{

MessageBox.Show(e.Message);

}

}






Re: Visual Studio Tools for Office Word Add-in not available while opening documents

Cindy Meister

Hi Chait

OK, here's your primary problem

private void CheckIfMenuBarExists()

{

try

{

Office.CommandBarPopup foundMenu = (Office.CommandBarPopup) //etc.

I see that you're declaring all the objects for the commandbars at the procedural level. This means that they go out of scope as soon as the procedure ends and GC (garbage collection) has had a chance to clean them up.

You need to declare the objects at the class level. Then you can instantiate them in the procedure. Your code would look more like this:

Office.CommandBarPopup cmdBarControl = null;

Office.CommandBarPopup foundMenu = null;

private void CheckIfMenuBarExists()

{

try

{

foundMenu = (Office.CommandBarPopup) //etc.

As to the Ribbon... Right now all your controls are showing up in the Add-ins tab ("menu") in the 2007 app, correct This probably isn't optimal because all customizations (the user's, yours and any from a third-party) will be all mixed up under this tab. If you leverage RibbonX you can create your own tabs in Office 2007 applications. Here's a good place to start.