Word 2007 ribbon dynamically adjust at startup

A

Axel

Hi,

in Word 2007 there is a global template "TEST.DOTM". Within the ribbon of
this template I've created the new tab "Test" wich contains 5 button.
Depending on user setting, some of these button should be visible and some
should not - after TEST.DOTM is loaded as global template. Here is the code:

XML code:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="CallbackOnRibbonLoad">
<ribbon startFromScratch="false">
<tabs>
<tab id="MyTab" label="Test">
<group id="MyGroup" label="Testgroup">
<buttonGroup id="MyButtonGroup">
<button id="Button1" imageMso="_1"
getVisible="CallbackGetVisible" tag="Macro1" />

<button id="Button2" imageMso="_2"
getVisible="CallbackGetVisible" tag="Macro2" />

<button id="Button3" imageMso="_3"
getVisible="CallbackGetVisible" tag="Macro3" />

<button id="Button4" imageMso="_4"
getVisible="CallbackGetVisible" tag="Macro4" />

<button id="Button5" imageMso="_5"
getVisible="CallbackGetVisible" tag="Macro5" />
</buttonGroup>
</group>
</tab>
</tabs>
</ribbon>
</customUI>


VBA code:

Public gobjRibbon As IRibbonUI
Public gbooRibbonButtonVisible As Boolean

'Global variable gobjRibbon intitialize at startup:
Public Sub CallbackOnRibbonLoad(ribbon As IRibbonUI)
Set gobjRibbon = ribbon
gbooRibbonButtonVisible = False 'All button fade out
End Sub

'Button visible/not visible:
Public Sub CallbackGetVisible(control As IRibbonControl, ByRef visible As
Variant)
visible = gbooRibbonButtonVisible
End Sub

Public Sub AutoExec()
Dim astrAllMacros(5) As String
Dim intI As Integer, strX As String

astrAllMacros(1) = "Button1"
astrAllMacros(2) = "Button2"
astrAllMacros(3) = "Button3"
astrAllMacros(4) = "Button4"
astrAllMacros(5) = "Button5"

gbooRibbonButtonVisible = True
strX = "10101" 'Only "Button1", "Button3" and "Button5" should be visible
For intI = 1 To 5
If Mid(strX, intI, 1) = "1" Then gobjRibbon.InvalidateControl
astrAllMacros(intI)
Next intI
End Sub

After that actually only "Button1", "Button3" and "Button5" should be
visible, but there are ALL button visible. Why?

I hope someone can help me.

Thanks in advance!
Axel
 
S

Summer

Hi, what is the problem? The code works for me by putting in the tab - and
does not call any macros - I removed CallbackOnRibbonLoad because I call
another routine. - but dumped it into my sample.dotm. It tried to open all 5
macros with error.

You might have to supply a macro sample - perhaps the code is incorrect?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top