What is best practice for using IRibbonControl callbacks?

6

62jsh

When using VB macros, one type of signature for a ribbon control callback is:
GetVisible(ByRef rctlRibbon As IRibbonControl, ByRef rboolVisible)

Is it best to use the reference to IRibbonControl to invalidate it
immediately, or,
if the callback occurs within a block code that has
Application.ScreenUpdating = False, will the IRibbonControl.Invalidate method
by popped from the stack?
What is the best practice from a Winword auotmation process?
 
C

Cindy M.

Hi =?Utf-8?B?NjJqc2g=?=,
When using VB macros, one type of signature for a ribbon control callback is:
GetVisible(ByRef rctlRibbon As IRibbonControl, ByRef rboolVisible)

Is it best to use the reference to IRibbonControl to invalidate it
immediately, or,
if the callback occurs within a block code that has
Application.ScreenUpdating = False, will the IRibbonControl.Invalidate method
by popped from the stack?
What is the best practice from a Winword auotmation process?
I don't really understand your question... Why would setting the ScreenUpdating
affect how the Ribbon callback is executed? It should execute, anyway, although
the change may not be visible to the user until the code has finished running.
(In Word, ScreenUpdating is re-enabled as soon as control returns to the user,
unlike in Excel.)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
T

Tony Jollans

Hi Cindy,

Off the top of my head I don't know for sure whether ScreenUpdating affects
the Ribbon, although I suspect not, and, like you, I don't really understand
the question, but ...
(In Word, ScreenUpdating is re-enabled as soon as control returns to the
user,
unlike in Excel.)

.. I don't understand what you're saying here. AFAIK, ScreenUpdating - in
Word and Excel - is a VBA setting that only has effect while code is
running, and it does not persist. Am I missing something?
 
G

Greg Maxey

Tony,

Off subject I know, but I don't think I really understand screen updating
(or refresh) in Word anyway. Can you offer, either here or a separate post,
an example of the best way to use screen updating,. refresh, or other
methods to streamline the running of code and minimize screen flicker?
Including when or if it is needed. Thanks.
 
C

Cindy M.

Hi Tony,
.. I don't understand what you're saying here. AFAIK, ScreenUpdating - in
Word and Excel - is a VBA setting that only has effect while code is
running, and it does not persist. Am I missing something?
Well, it's been a while since I last did anything serious with Excel, but in
the past I seem to recall that ScreenUpdating = False stayed in effect for
Excel, even after the code was finished running - that we had to remember to
set it back to True. But perhaps that's changed, or my brain is mis-firing
and it was something else at the application level that was significantly
different for the two.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
T

Tony Jollans

Thanks, Cindy,

You may be right. This is something there is some confusion and
misunderstanding about - not helped by the Help - and it may well have
changed at some time in either or both of the applications. AFAIK, now, both
apps are the same and it doesn't need resetting.
 
G

Gary Hillerson

My guess is that you're asking how to use the GetVisible callback to
control the visibility of certain controls in the ribbon.

Here's a simple example for a ribbon in which you want to special-case
a few of your buttons and have the others on unconditionally

Sub MyGetVisibleFcn(control As IRibbonControl, ByRef returnedVal)
Select Case control.id
Case "My1stButton"
returnedVal = IsButtonOn(1)
Case "My2ndButton"
returnedVal = IsButtonOn(2)
Case "My3rdButton"
returnedVal = IsButtonOn(3)
Case "My4thButton
returnedVal = NotIsButtonOn(1)
Case "My5thButton"
returnedVal = Not IsButtonOn(2)
Case "My6thButton"
returnedVal = Not IsButtonOn(3)
Case Else
returnedVal = True
End Select
End Sub

You then have to make sure that you put the
GetVisible="MyGetVisibleFcn" property in your ribbon.xml for any
controls that you want to control the visibility of. Each control's
GetVisible function will be called when the document opens.

If you want to manually trigger your GetVisible function in response
to some event, you need to invalidate the control. To invalidate the
control, you have to have the ribbon's handle (the IRibbonUI handle).
As far as I can tell, you can only grab that handle when your document
is opened (or created), which you do by creating an Onload function
for the ribbon, and adding the onLoad property to your ribbon.xml
file:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="MyRibbonLoadFcn">

Dim ribbonHdl as IRibbonUi

Sub MyRibbonLoadFcn(ribbon As IRibbonUI)
Set mRibbon = ribbon
End Sub


Then you can write a function that invalidates controls, which forces
their GetVisible to be called:

Sub InvalidateButton(buttonName)
'Whatever logic you need to make your MyGetVisibleFcn work
' correctly for the button when it gets called, then:

call mRibbon.InvalidateControl(buttonName)
End Sub

- Gary
 

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