none
Word Custom Ribbon Button disappears after Save As (sometimes) RRS feed

  • Question

  • Hi folks, I have a document (template) based solution (VSTO 3, VS 2008) with a custom ribbon created in Ribbon Designer. If I save the document under another name, and then click on my new ribbon tab, the control I placed there has disappeared, and I’m not able to launch my solution. The strange thing is, if I click on the custom tab before saving the document, the button stays put, and is even still there after I close and reload.

    I’ve tried adding Globals.Ribbons.Ribbon1.Button1.Visible = True  and Globals.Ribbons.Ribbon1.Button1.Enabled = True to every ThisDocument event handler I can think of but no luck. Any suggestions?
    Tuesday, June 30, 2009 3:09 AM

Answers

  • I found the solution here:

    http://blogs.msdn.com/b/vsod/archive/2009/12/15/excel-2007-ribbon-tabs-tabaddins-disappear-from-doc-level-customizations-if-user-opens-and-closes-a-doc-running-in-the-same-instance-of-excel.aspx

     

    private void ThisWorkbook_Startup(object sender, System.EventArgs e)
    {
    //...
     Application.WindowActivate += new Excel.AppEvents_WindowActivateEventHandler(Application_WindowActivate);
    //...
    }
    
    void Application_WindowActivate(Excel.Workbook Wb, Excel.Window Wn)
    {
     Globals.ThisWorkbook.Application.CommandBars["Standard"].Controls[1].OnAction = "abc";
     Globals.ThisWorkbook.Application.CommandBars["Standard"].Controls[1].OnAction = "";
    }

    It's not very elegant but it works and now the ribbon reappears.

     

    • Proposed as answer by _ziMarrio_ Wednesday, July 21, 2010 11:56 AM
    • Marked as answer by Tim Li Wednesday, July 21, 2010 1:22 PM
    Wednesday, July 21, 2010 11:56 AM
  • Hi Patrick

    Where (what folder location) are you saving the document? If it's not back to the Bin folder, that would explain why you lose the buttons - the VSTO solution is probably being detached from the document, or the folder location is not a "Trusted" location in Word 2007.

    I'm guessing that once you close, then re-open the document the buttons are gone, even if they were visible before closing?

    The Ribbon doesn't work 100% correctly when it comes to displaying/hiding buttons in all circumstances. (IOW that the buttons are still visible in the one scenario is likely a small bug in the Ribbon design.) I've been programming a project this week where buttons sometimes latently appear where they should not. But once I restart Word, the anomalies disappear.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Tim Li Thursday, July 9, 2009 2:35 AM
    Wednesday, July 8, 2009 8:20 AM
    Moderator

All replies

  • I'm still interested in an answer to this question, but since time is short I moved the control to the Office Button, where it behaves as expected. This is actually more appropriate anyway from a UI design point of view; adding a new ribbon tab for a single command seems like overkill.

    Cheers,

    Patrick
    Tuesday, June 30, 2009 8:35 PM

  • I’ve tried adding Globals.Ribbons.Ribbon1.Button1.Visible = True  and Globals.Ribbons.Ribbon1.Button1.Enabled = True to every ThisDocument event handler I can think of but no luck. Any suggestions?

    Can you make sure your code is still running?
    Do you receive any error message during the startup process of Word?
    It's hard to say what's going on, can you reproduce this issue if build another simple solution?(just drag a button in a Ribbon designer,then compile)

    Please check this link for the details of How a document-level customization load in Office application.
    http://msdn.microsoft.com/en-us/library/zcfbd2sk.aspx

    Thanks
    We have published a VSTO FAQ recently, you can view them from the entry thread VSTO FAQ.
    If you have any feedbacks or suggestions on this FAQ, please feel free to write us emails to colbertz@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, July 6, 2009 9:54 AM
  • Hi Tim, thanks for your response. I have been able to reproduce this behavior with a simple solution. Here's what I did: create a new doc template project, add a ribbon and button in ribbon designer, and build the solution. Exit Visual Studio, click on the .dotx in the bin directory, save the new doc, then click to the Add In tab. You'll see that the button has disappeared.

    However if switch to the Add In tab before saving the doc, the button stays in place and is still acessible.

    Thanks,

    Patrick
    Tuesday, July 7, 2009 9:21 PM
  • Hi Patrick

    Where (what folder location) are you saving the document? If it's not back to the Bin folder, that would explain why you lose the buttons - the VSTO solution is probably being detached from the document, or the folder location is not a "Trusted" location in Word 2007.

    I'm guessing that once you close, then re-open the document the buttons are gone, even if they were visible before closing?

    The Ribbon doesn't work 100% correctly when it comes to displaying/hiding buttons in all circumstances. (IOW that the buttons are still visible in the one scenario is likely a small bug in the Ribbon design.) I've been programming a project this week where buttons sometimes latently appear where they should not. But once I restart Word, the anomalies disappear.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Tim Li Thursday, July 9, 2009 2:35 AM
    Wednesday, July 8, 2009 8:20 AM
    Moderator
  • Thanks Cindy. Well, here's the strange thing, which I hadn't tried before. After following the "disappearing button" steps described above and noting that the button indded did not display, I exited Word, then started Word up again, and the button was there with no problem. Sounds like the same thing you're experiencing.

    By the way, I managed to reproduce all the above-mentioned behaviors after publishing the simple solution, installing it on my machine, and then running it from, and saving it to, the Documents folder. Is this worth passing on to the Word team?
    Wednesday, July 8, 2009 9:55 PM
  • Thanks Cindy. Well, here's the strange thing, which I hadn't tried before. After following the "disappearing button" steps described above and noting that the button indded did not display, I exited Word, then started Word up again, and the button was there with no problem. Sounds like the same thing you're experiencing.

    By the way, I managed to reproduce all the above-mentioned behaviors after publishing the simple solution, installing it on my machine, and then running it from, and saving it to, the Documents folder. Is this worth passing on to the Word team?

    Hi Patrick

    If you have an "in" to the Word team, then go for it :-)

    But the Ribbon UI is not their baby. It belongs to a separate UI group, headed by Jensen Harris.
    Cindy Meister, VSTO/Word MVP
    Thursday, July 9, 2009 7:02 AM
    Moderator
  • Cindy,

    I came across this thread today while trying to debug my VSTO application.

    It's xlsm / VB.net application that creats a customized Ribbon to excel 2007. The new tabl is called 'My Function' which has its own drop down fields to initialize.

    It launches successfully and once I click on 'My Function', everything loads perfectly.

    So far so good.  But once I open another regular excel document, it opens within the same excel instance and it doesn't have 'My Function' which is normal. But once I switch back to the excel xlsm which has 'My Function'  tab, the new tab disappears.

    I've tried RibbonUI.Invalidate() but it didn't help. Any clue?

    Thanks,

    Bintao

    Monday, July 12, 2010 7:03 PM
  • I have the same problem!!

    I have a ribbon in an excel document that is working perfectly but, when I open a regular excel document and switch back to the ribbon document the ribbon isn't there anymore.

     

    I would really appreciate any help as this is really annoying to the users.

     

    Thanks,

    Mário

     

     

    Wednesday, July 21, 2010 11:37 AM
  • I found the solution here:

    http://blogs.msdn.com/b/vsod/archive/2009/12/15/excel-2007-ribbon-tabs-tabaddins-disappear-from-doc-level-customizations-if-user-opens-and-closes-a-doc-running-in-the-same-instance-of-excel.aspx

     

    private void ThisWorkbook_Startup(object sender, System.EventArgs e)
    {
    //...
     Application.WindowActivate += new Excel.AppEvents_WindowActivateEventHandler(Application_WindowActivate);
    //...
    }
    
    void Application_WindowActivate(Excel.Workbook Wb, Excel.Window Wn)
    {
     Globals.ThisWorkbook.Application.CommandBars["Standard"].Controls[1].OnAction = "abc";
     Globals.ThisWorkbook.Application.CommandBars["Standard"].Controls[1].OnAction = "";
    }

    It's not very elegant but it works and now the ribbon reappears.

     

    • Proposed as answer by _ziMarrio_ Wednesday, July 21, 2010 11:56 AM
    • Marked as answer by Tim Li Wednesday, July 21, 2010 1:22 PM
    Wednesday, July 21, 2010 11:56 AM
  • _ziMarrio_,

    YOU ARE THE MAN!!!!

    THANKS A TRILLION!!!!

     

    BINTAO

    Wednesday, July 21, 2010 1:01 PM
  • I have the same problem - where do I put this code? Thanks

    I found the solution here:

    http://blogs.msdn.com/b/vsod/archive/2009/12/15/excel-2007-ribbon-tabs-tabaddins-disappear-from-doc-level-customizations-if-user-opens-and-closes-a-doc-running-in-the-same-instance-of-excel.aspx

     

    private void ThisWorkbook_Startup(object sender, System.EventArgs e)
    {
    //...
     Application.WindowActivate += new Excel.AppEvents_WindowActivateEventHandler(Application_WindowActivate);
    //...
    }
    
    void Application_WindowActivate(Excel.Workbook Wb, Excel.Window Wn)
    {
     Globals.ThisWorkbook.Application.CommandBars["Standard"].Controls[1].OnAction = "abc";
     Globals.ThisWorkbook.Application.CommandBars["Standard"].Controls[1].OnAction = "";
    }
    

    It's not very elegant but it works and now the ribbon reappears.

     

    Wednesday, October 5, 2011 2:40 PM