Consulting

Results 1 to 11 of 11

Thread: Solved: Word 2007 Ribbon Tab visibility

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location

    Exclamation Solved: Word 2007 Ribbon Tab visibility

    Hi,

    I'm trying to make Word 2007 tabs visible/invisible through XML and callbacks. I am able to do it with custom tabs, but not with MSO tabs.


    Does anyone know if this is possible?

    Thanks

    Jason

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Jason, and welcome to VBAX.

    Absolutely this is possible. Here's an example of referring to the tab:

    <tab idMso="TabView" getVisible="rxtabMsoView_GetVisible"/>

    Then, you'd use a callback as follows to trigger the state:
    [VBA]Sub rxtabMsoView_GetVisible(control As IRibbonControl, ByRef returnedVal)
    returnedVal = False
    End Sub[/VBA]

    Of course, you wouldn't hard-code false, but rather link it to another routine or property. You'd probably also want to set up the ability to invalidate the Ribbon by capturing the RibbonUI object so that you can get it back on demand.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    Ken,

    thanks for the reply, but that solution doesn't seem to be working. Here is my XML.....basically straight from the RibbonX book.

     
    <tab idMso ="TabPageLayoutWord"
    getVisible="rxtabMsoPageLayoutWord_GetVisible"
     
    <toggleButton id="rxtglCustomReview"
    label="Toggle Custom Review Tab"
    imageMso="ReviewAcceptChangeMenu"
    size="large"
    getPressed="rxtglCustomReview_getPressed"
    onAction="rxtglShared_Click"/>

    And here is the VBA

    [vba]
    Public grxIRibbonUI As IRibbonUI
    Public gblnShowCustomReviewTab As Boolean
    Function getRegistry(ByVal strkey As String) As Boolean
    On Error Resume Next
    getRegistry = GetSetting("Escrow", "TabVisibility", strkey)
    If Err <> 0 Then getRegistry = False
    End Function

    Function saveRegistry(ByVal strkey As String, ByVal blnsetting As Boolean)
    SaveSetting "Escrow", "TabVisibility", strkey, blnsetting
    End Function

    Sub rxIRibbonUI_onLoad(ribbon As IRibbonUI)
    Set grxIRibbonUI = ribbon
    End Sub

    Sub rxtglCustomReview_getPressed(control As IRibbonControl, ByRef returnedval)
    returnedval = getRegistry("TabPageLayoutWord")
    gblnShowCustomReviewTab = getRegistry("TabPageLayoutWord")
    grxIRibbonUI.InvalidateControl ("TabPageLayoutWord")
    End Sub

    Sub rxtglShared_Click(control As IRibbonControl, pressed As Boolean)
    Select Case control.ID
    Case "rxtglCustomReview"
    gblnShowCustomReviewTab = pressed
    saveRegistry "TabPageLayoutWord", pressed
    gblnCalledOnOpen = False
    End Select
    Call rxtglCustomReview_getPressed(Nothing, gblnShowCustomReviewTab)
    grxIRibbonUI.Invalidate
    End Sub
    Sub rxtabMsoPageLayoutWord_GetVisible(control As IRibbonControl, ByRef returnedval)
    returnedval = gblnShowCustomReviewTab
    End Sub
    [/vba]

    Clicking on the toggle button has no effect, the Tab does not appear or disapper. This code works perfectly if I refer to a custom tab.

    Thanks

    Jason

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Jason,

    A couple of questions for you:
    1) Did you validate the XML code with the customUI editor?
    2) Do you have the "Show Add-in User Interface Errors" checkbox selected in Word? (Office Menu-->Word Options-->Advanced-->Last checkbox, right above the address box)

    I'm only asking, because the XML I copied from above was missing a closing > on the tab.

    The real issue is in the VBA, specifically the invalidation of the Ribbon. Instead of attempting to invalidate the specific tab, in the rxtglCustomReview_getPressed routine, invalidate the entire Ribbon.

    [vba]grxIRibbonUI.Invalidate[/vba]
    Also, you can cut the following extraneous line from rxtglShared_Click:

    [vba]gblnCAlledOnOpen = False[/vba]

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    Hi Ken,

    To answer both of your questions,

    1) I did validate the XML code, I'm guessing I missed a > when I copied into this post.
    2) The "Show Add-in User Interface Errors" checkbox is checked in Word.

    I also cleaned up my VBA, invalidating the ribbon instead of the specific tab, and removed the extraneous code from rxtglshared_click.


    Still have the same results.......

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Jason,

    I've uploaded the document that I used for testing. Check the Custom tab at the end for the toggleButton.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  7. #7
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    Hi Ken,

    Okay I think I have diagnosed the problem on my end. Since we need to control what the users are doing, we have to manipulate the QAT, therefore "startFromScratch" is set to true.

    setting it to False fixes the Tab visibility issue, but raises others....

    Is there are way for this to work with startFromScratch set to True?

    Thanks

    Jason

  8. #8
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Ah...

    Yes, this is a bug, and I reported it to MS tonight. In the mean time, the only workaround that I'm aware of is to create a custom tab, label it the same, and populate it with the msoGroups that are on the tab you wish to replicate. (As you discovered, the getVisible callback works for cusotm tabs, just not the Mso tabs.) Painful, but it will be seemless to the user.

    Wish I could give you better news,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  9. #9
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    Thanks for your Help Ken, I suspected the Start From Scratch was causing problems.

    One more quick question, will I have the same issue in Excel?

    Thanks

    Jason

  10. #10
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by jromano
    will I have the same issue in Excel?
    You bet.

    I discussed this with my co-author, and he suggested that the other route to the same end is to leave startFromScratch as false, but add callbacks to each of the MsoTabs to toggle them. This would allow you to hide them all at startup and call them up when needed.

    It could be a longer route to the same end, but is another way of looking at the issue.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  11. #11
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    Thanks for all your help, Ken,

    I am going to mark this as solved, even though it is not the solution I was hoping for. The start from scratch suggestion=false you had will not work, because I need to manipulate the QAT.

    Jason

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •