PDA

View Full Version : Solved: Word 2007 Ribbon Tab visibility



jromano
05-21-2008, 03:08 PM
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

Ken Puls
05-21-2008, 09:04 PM
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:
Sub rxtabMsoView_GetVisible(control As IRibbonControl, ByRef returnedVal)
returnedVal = False
End Sub

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.

jromano
05-22-2008, 07:20 AM
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


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


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

Ken Puls
05-22-2008, 10:21 PM
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.

grxIRibbonUI.Invalidate
Also, you can cut the following extraneous line from rxtglShared_Click:

gblnCAlledOnOpen = False

HTH,

jromano
05-23-2008, 07:20 AM
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.......

Ken Puls
05-23-2008, 08:35 AM
Hi Jason,

I've uploaded the document that I used for testing. Check the Custom tab at the end for the toggleButton.

jromano
05-23-2008, 02:21 PM
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

Ken Puls
05-23-2008, 10:32 PM
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,

jromano
05-27-2008, 07:43 AM
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

Ken Puls
05-28-2008, 10:00 PM
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.

jromano
05-29-2008, 07:20 AM
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