I am trying to change the KeyTip property of the RibbonTab object I have created. When I run my addin in Excel it shows the KeyTip is "X" and not "JJJ".
If I change it in the Properties window to "JJJ" it works fine but I want to understand why I cannot change it this way.
What do I need to do to get the RibbonTab.KeyTip property to load as "JJJ"?
(FYI this is my first project so I am still learning)
Thanks,
Imports Microsoft.Office.Tools.Ribbon
Public Class Ribbon1
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
tabRibbon1.KeyTip = "JJJ"
End Sub
The Fluent UI (aka Ribbon UI) is a static thing from its birth. You may set up the keytip attribute only once at startup when your add-in returns the UI markup (generated by the Ribbon designer or just a raw XML markup).
Also you may consider using the getKeyTip callback which allows to evaluate keyboard shortcuts dynamically. The Invalidate method of the IRibbonUI interface invalidates the cached values for all of the controls of the Ribbon user interface. You can customize the Ribbon UI by using callback procedures in COM add-ins. For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method. For example:
Dim MyRibbon As IRibbonUI
Sub MyAddInInitialize(Ribbon As IRibbonUI)
Set MyRibbon = Ribbon
End Sub
Sub myFunction()
MyRibbon.Invalidate() ‘ Invalidates the caches of all of this add-in’s controls
End Sub
You may also find the InvalidateControl method of the IRibbonUI interface helpful. It invalidates the cached value for a single control on the Ribbon user interface.
Read more about the Ribbon UI in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
and
Chapter 11: Creating Dynamic Ribbon Customizations (1 of 2)
Chapter 11: Creating Dynamic Ribbon Customizations (2 of 2)
Related
we are using the Application.DocumentChange event so that when a document is loaded, it can check the name of the document, and then if it is named in a certain way show or hide buttons on the ribbon.
If I use the code below it works really well, it shows or hides the buttons correctly.
But when I run the addin in debug mode from Visual Studio, when the document is closing it gives this message.
System.Runtime.InteropServices.COMException: 'This command is not available because no document is open.'
As you can see I tried to put in an if statement to stop it running the code but it didnt work.
If I just install my addin, Word does not seem to crash or have any problems, maybe I shouldnt worry about it?
Thanks
Private Sub Application_DocumentChange() Handles Application.DocumentChange
If Globals.ThisAddIn.Application.Documents.Count > 0 Then
If Globals.ThisAddIn.Application.ActiveDocument.BuiltInDocumentProperties("Title").Value = "Document Name Here" Then
Globals.Ribbons.VisualfilesTab.AttachEvidence.Visible = True
Else
Globals.Ribbons.VisualfilesTab.GetAuthorisation.Visible = True
End If
End If
End Sub
Consider switching your custom UI to the ribbon XML over the designer-generated custom ribbon UI. You can export your existing custom UI to the ribbon XML markup. See How to: Export a ribbon from the Ribbon Designer to Ribbon XML for more information.
You can customize the Ribbon UI by using callback procedures in COM add-ins. For each of the callbacks that the add-in implements, the responses are cached.
For example, if an add-in writer implements the getVisible callback procedure for a button, the function is called once, the state is loaded, and then if the visibility state needs to be updated, the cached state is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate or IRibbonUI.InvalidateControl method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.
Read more about the the Fluent UI (aka Ribbon UI) in the following articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
I have a couple of button is an MS access application that need to be enabled or disabled at the same time. When one of them is clicked and opens a form they both need to be set to disabled. When the form is closed they both need to be set to enabled.
I have no problem doing this for the control that is clicked. But I don't know how to reference the one that was not clicked.
Here is the code for my ribbon:
and the funciton I use to handle getEnabled:
How do I disabled or enable both buttons at the same time?
You need to use the IRibbonUI.Invalidate or IRibbonUI.InvalidateControl methods to get your callback invoked for other controls. The invalidate method allows invalidating the cached values for all of the controls of the Ribbon user interface.
For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.
Dim MyRibbon As IRibbonUI
Sub MyAddInInitialize(Ribbon As IRibbonUI)
Set MyRibbon = Ribbon
End Sub
Sub myFunction()
MyRibbon.Invalidate() ' Invalidates the caches of all of this add-in's controls
End Sub
The Fluent UI (aka Ribbon UI) is described in depth in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
I would like to use a getLabel callback from some custom XML in a PowerPoint ppam in order to localise text in the Ribbon. My concern is that doing this could cause error messages to appear from time to time when starting PowerPoint ("PowerPoint can't start this feature because you currently have a Visual Basic for Applications project in break mode.") as users have experienced with an add-in that uses a getEnabled callback. I have already asked a question about other options for localising the ribbon.
Do you use getLabel in a PowerPoint ppam add-in? If so, do you sometimes see this error message when PowerPoint is started? Additionally, do you use getEnabled, and does this ever cause this error message to be displayed when PowerPoint starts up?
Answers either way would be great.
This is what I am testing:
Custom UI XML fragment:
<button id="app1ShowAMsg"
imageMso="TableInsert"
size="normal"
onAction="app1ShowAMessage"
label="app1GetLabel"/>
VBA code:
Public Sub app1GetLabel(control As IRibbonControl, ByRef returnedVal)
Select Case control.Id
Case "app1ShowAMsg"
returnedVal = "My added label"
End Select
End Sub
Public Sub app1ShowAMessage()
MsgBox "You clicked a button."
End Sub
Yes, it is. I don't see anything strange in using the getLabel callback along with others. Moreover, that is the recommended way of implementing any dynamism on the Fluent UI - for changing the caption string and etc. at runtime. The Fluent UI is described in depth in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
Also you may find the following articles helpful:
Chapter 11: Creating Dynamic Ribbon Customizations (1 of 2)
Chapter 11: Creating Dynamic Ribbon Customizations (2 of 2)
I'm writting AddIn for PowerPoint 2010. I'm using two functions of PowerPoint.
Application_PresentationBeforeSave(ByVal Pres As Microsoft.Office.Interop.PowerPoint.Presentation, ByRef Cancel As Boolean)
Application_PresentationSave(ByVal Pres As Microsoft.Office.Interop.PowerPoint.Presentation)
When I perform Save operation (Ctrl+S) or SaveAs (File -> SaveAs) on powerpoint it executes Application_PresentationBeforeSave() method.
But I need to differentiate these two calls (Ctril+S & SaveAs) and accordingly perform some task. So how can I differentiate these two calls in BeforeSave method ??
As for Word, in Application_DocumentBeforeSave(ByVal Doc As Microsoft.Office.Interop.Word.Document, ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) there is SaveAsUI flag which differentiate whether this method has been called by SaveAs or Ctrl+S action.
So is there any flag/property which differtiate same things in PowerPoint ??
You need to repurpose the ribbon buttons or replace the backstage UI controls with your own so you will know what action users chose in the UI. In case of ribbon controls see the Temporarily Repurpose Commands on the Office Fluent Ribbon article in MSDN. The Backstage UI is described in the following articles in MSDN in depth:
Introduction to the Office 2010 Backstage View for Developers
Customizing the Office 2010 Backstage View for Developers
In case of Ctrl+S shortcuts you need set a keyboard hook using Windows API functions, see Using shortcut keys to call a function in an Office Add-in for more information.
Thanks Eugene for showing me a way.
My problem got resolve. I tried your suggestion.
Here is the description of my solution.
I have added function call in Ribbon.xml
In MySaveAs() function I set one glbal variable. And used it in BeforeSave mthod.
I am trying to add a macro to the quick access toolbar through vba code.
I am also wondering how to add a macro key shortcut through vba code.
This is all for windows 2007.
For keyboard shortcut, use:
Application.OnKey
To add to the quick access toolbar, first, you need a reference to the ribbon itself. I had a project where I gave my custom ribbon a custom "onload" function, and then captured the ribbon object in that function. Then, use that object to make changes. Sadly, sometimes this object "disappears" in VBA, and there's not much you can do except have a backup of the object reference, and usually one of them is still active.
See this link for an add-in approach:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
I used this ribbon editor for my project.
Here's how I captured the ribbon object with a custom onload function:
'Callback for customUI.onLoad
Sub RibbonLoaded(ribbon As IRibbonUI)
Set myRibbon = ribbon
Set myRibbonBackup = ribbon
End Sub
I would recommend using the ribbon editor tool I gave you as much as possible, rather than trying to edit the ribbon with VBA--it can be quite difficult. I've never used VBA to modify the quick access toolbar.