Home » .Net FrameworkRSS

Customized Office Ribbon does not show up in VSTO Word Template

Hello,

I am working on a VSTO Word Template. And I have created a customized Ribbon with five Ribbon Groups. I am facaing issues with the Ribbon. Sometimes the Ribbon appears without any buttons. I have noticed the following behavior.

Scenario #1

Create a document based on the customized Word template. Switch to the Customized Ribbon Tab. Everything looks fine - the ribbon is fully loaded with all buttons and menu options.

Scenariio #2

Create a document based on the customized Word template. Before switching to Customized Ribbon Tab, Save the document. Now switch to the Customized Ribbon Tab. The Ribbon is blank. No buttons are loaded. Howerver I could see Ribbon Group Labels.

Scenariio #3

Create a document based on the customized Word template. Before switching to Customized Ribbon Tab, Publish this document to a SharePoint Document Library (File -> Publish -> Document Management Server). Now switch to the Customized Ribbon Tab. The Ribbon is blank. No buttons are loaded. Howerver I could see Ribbon Group Labels.

Steps I have already tried:

Edited this file C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.Office2007.targets and set the load behaviour to 16. Restarted VS, republished the template, re-installed the template.
<LoadBehavior>16</LoadBehavior> 
Simulated Alt+Z (as Z is the Key Tip) to activate the customized tab when the document is loaded. But this results in application crash.
SendKeys.Send("%Z");

Environment details:

Microsoft Visual Studio 2008
Version 9.0.30729.1 SP Microsoft .NET Framework
Version 3.5 SP1 Microsoft SharePoint Foundation 2010 Microsoft Office Word 2007
12.0.6514.5000 SP2 MSO (12.0.6425.1000)
 

11 Answers Found

 

Answer 1

Hi Sahil

FWIW this has been reported before, although I don't know of a "solution" for Word. For example:

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/5abbe3ee-51c1-4de6-8f97-c2590c52931d

 

Answer 2

Cindy thanks for the prompt reply.

I added the following code and now I get the following messages:

When I save  the document  - "Do you also want to save changes to the document template?"

When I close the document - "You have modified styles, building blocks (such as cover pages or headers), or other content that is stored in ***.dotx. Do you want to save changes to ***.dotx?"

privatevoid ThisDocument_Startup(object sender, System.EventArgs e)
{
 Application.WindowActivate += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowActivateEventHandler(Application_WindowActivate);
}

void Application_WindowActivate(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)
{
 Globals.ThisDocument.Application.CommandBars["Standard"].Controls[1].OnAction = "abc";
 Globals.ThisDocument.Application.CommandBars["Standard"].Controls[1].OnAction = "";
}
 

Answer 3

Hi Sahil

At the end of any procedure where you call the Commandbars object, add:

Globals.ThisDocument.Application.NormalTemplate.Saved = true;

Does that help?

 

Answer 4

Nope, I still see both the messages (as mentioned in my last post on saving and on closing the document) even after adding that line of code:

void Application_WindowActivate(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)
{
  Globals.ThisDocument.Application.CommandBars["Standard"].Controls[1].OnAction = "abc";
  Globals.ThisDocument.Application.CommandBars["Standard"].Controls[1].OnAction = "";
  Globals.ThisDocument.Application.NormalTemplate.Saved = true;
}
 

Answer 5

I have found another scenario  where it still fails to load  the Ribbon.

Scenariio #4

Open Word 2007. Open a document  from SharePoint document library  (this document was created  using cusomized tempate and published to SharePoint as per Scenario #3) . Remember for this library the following versioning setting is set to Yes.
Require documents to be checked out before they can be edited. (Yes) Word will open the document and give you a "Check Out" button under the Ribbon. Click the button to Check Out the document. Now switch  to the Customized Ribbon Tab. The Ribbon is blank. No buttons  are loaded. Howerver I could see Ribbon Group Labels.

I have added the SharePoint document library URL as a Trusted Location in Word 2007 Options.

 

Answer 6

Hi Sahil

Ah, sorry, I think I forgot this is a Template project (not an Add-in).

Try this instead:

ThisDocument.AttachedTemplate.Saved = true;

Background: What's happening is that changed state of CommandBars is saved to a "customization context". It's a bit of a lottery what this could be, but with VSTO documents/templates it's usually that document  or its template  (and not Normal, which is where my head was). In this case, it seems pretty clear it's your Template project (on which the document is based).

 

Answer 7

Hi Cindy,

I tried the following as ThisDocument.AttachedTemplate.Saved = true; was giving static context error.

void Application_WindowActivate(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)
{
 Globals.ThisDocument.Application.CommandBars["Standard"].Controls[1].OnAction = "abc";
 Globals.ThisDocument.Application.CommandBars["Standard"].Controls[1].OnAction = "";
   
 var attachedTemplate = (Word.Template) AttachedTemplate;
 if (attachedTemplate != null) attachedTemplate.Saved = true;
}

And it worked for Scenario #2 and #3 but it did not work for Scenario #4. I have noticed  that this is an issue only with the buttons  placed inside Menu
Control. Buttons placed directly in the Ribbon Group loads perfectly. FYI - The first Ribbon Group has a single Ribbon Menu which contains four Ribbon Buttons.

Scenario #4

Open Word 2007. Open a document  from SharePoint document library  (this document was created  using cusomized tempate and published to SharePoint as per Scenario #3) . Remember for this library the following versioning setting is set to Yes.
Require documents to be checked out before they can be edited. (Yes) Word will open the document and give you a "Check Out" button under the Ribbon. Click the button to Check Out the document. Now switch  to the Customized Ribbon Tab. No buttons placed inside Menu Control are loaded.

Sometimes I see this happening at design time too.

 

Answer 8

Hi Sahil

You'll probably have to go through the paid support channels and report this as a bug.

Note on AttachedTemplate: document.get_AttachedTemplate in C#

 

Answer 9

Cindy,

Thank you so much for all your efforts and time. I will report this as a bug. Otherwise the problem where the customized ribbon  was not loading properly is fixed.

Thanks again.

-Sahil.

 

Answer 10

Hi Sahil

Thanks for confirming that, and for showing us that the original Excel workaround also applies to Word :-)

I apologize for my brain not always picking up on your environment  correctly - thank you for your patience!

 

Answer 11

Cindy,

I know you are going to hate me for this but the above fix still does not work for Scenario #4. The complete ribbon (and not just the buttons  placed in Menu) fails to load  when you check out a document  from SharePoint. I would appreciate any insight on this.

Scenariio #4

Open Word 2007. Open a document from SharePoint document library  (this document was created  using cusomized tempate and published to SharePoint as per Scenario #3) . Remember for this library the following versioning setting is set to Yes.
Require documents to be checked out before they can be edited. (Yes) Word will open the document and give you a "Check Out" button under the Ribbon. Click the button to Check Out the document. Now switch  to the Customized ribbon  Tab. The Ribbon is blank. No buttons are loaded. Howerver I could see Ribbon Group Labels.

I have added the SharePoint document library URL as a Trusted Location in Word 2007 Options.

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter