Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Word 2007 ribbon dynamically adjust at startup

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Axel - 28 Mar 2008 13:13 GMT
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
Summer - 29 Mar 2008 00:02 GMT
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?

> Hi,
>
[quoted text clipped - 77 lines]
> Thanks in advance!
> Axel
Summer - 29 Mar 2008 10:51 GMT
Sorry, did not see the macros at end.
> Hi,
>
[quoted text clipped - 77 lines]
> Thanks in advance!
> Axel

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.