Is getLabel safe to use (VBA, PowerPoint)? - vba

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)

Related

Word VSTO - Document Changed Event

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)

Right click shortcut menu code locks shared database every time

I have a compiled Access database with a front-end (where this code is running) and compiled back end data storage.
I have code to create a shortcut menu, if inserted into the start-up routine of the database, MS Access ignores the default setting to open as shared mode on the Access database, and opens as Exclusive mode. This is causing a lot of problems.
Public Sub sbCreateReportShortCutMenu()
Dim cmbRightClick as Office.CommandBar
Set cmbRightClick = CommandBars.Add("cmdFormRightClick", 0,, True)
Set cmbRightClick = Nothing
End Sub
Moving the code so it only runs when needed (before opening forms in this case), the issue still occurs. If the first user in the database opens a form which requires this code, and nobody else is in the database at the time, the database goes in to exclusive mode and other people can't access it.
All PCs/people accessing the database front end have Access set to shared/no locks as default.
What is it about this code causing the shared database to lock? Any ideas please? Thank you in advance
CommandBars were deprecated. You need to use the Fluent UI for customizing Office UI. Read more about 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)

Disabling buttons in the default ribbon in PowerPoint

I am looking for a solution to disable the button "Slide Master" in PowerPoint when someone opens a specific template / PowerPoint file. The reason is to stop basic user to change layouts (basically the master).
The macro I guess, must also allow that specific users (Power Users) are able to enable that button by inserting a passwort. I have nevery programmed anything around the ribbon. Can someone help me with this task?
You can try repurposing the built-in control. See Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.
Also you may define the getEnabled callback for the button where you can manage the enabled state dynamically. The signature of the getEnabled callback looks in the following way:
C#: bool GetEnabled(IRibbonControl control)
VBA: Sub GetEnabled(control As IRibbonControl, ByRef enabled)
C++: HRESULT GetEnabled([in] IRibbonControl *pControl, [out, retval] VARIANT_BOOL *pvarfEnabled)
Visual Basic: Function GetEnabled(control as IRibbonControl) As Boolean
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)

How to create toggle button for Macro

I have created a macro that will set the categories of out going mail without needing to open the tag dialog. I have added the macro to the ribbon via the "Customize Ribbon" options on outlook itself. That macro works fine, however I would like the button to be highlighted (toggled on) when the category is set and then regular (toggle off) when the category is no longer set.
I only have basic VB knowledge but have good knowledge of java so the concepts are familiar just not the syntax. This is also the first macro I've ever done.
I have tried searching Google and Stack for an answer but I think due to my lack of knowledge I'm not using the correct keyword to get a useful result.
Thanks for the help.
VBA macros don't allow creating a custom ribbon UI. You need to develop a COM add-in if you want to customize the Fluent UI by adding a toggle button to the Outlook window.
Take a look at the following articles to create a custom ribbon UI:
Walkthrough: Create a custom tab by using the Ribbon Designer
Walkthrough: Create a custom tab by using Ribbon XML
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)

How to make changes in Ribbon elements of a single excel instance, using application-level add-in?

I'm using VSTO with VB.NET for Excel 2013. I'm developing an application-level add-in, but I can't make two different workbooks store different "ribbon state". For example, when I want to enable a button, I use the following code:
Globals.Ribbons.Ribbon1.myButton.Enable = False
This makes the element "myButton" to be disabled on each opened workbook, but I want to make it disabled only for one workbook.
The way I'm doing now is to handle the event WorkbookActivate, to change the ribbon state. The problem is: this way, the user sees an invalid state at other workbooks that are not on the top.
There is some better workaround? There isn't a way to manage the ribbon instances (and not only the global element as I am doing)?
Thanks
There is some better workaround? There isn't a way to manage the ribbon instances (and not only the global element as I am doing)?
You need to use callbacks instead. Try to use the getEnabled callback instead.
Moreover, when required you can use the IRibbonUI interface methods to force Office applications to update the UI controls. The Invalidate method invalidates the cached values for all of the controls of the Ribbon user interface. See Overview of the IRibbonUI Object .
You can read more about the Ribbon UI (aka Fluent UI) in the following series of articles in MSDN:
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)