And the following code in my VBA project (not developed for me, as I mentioned I'm new on this)
Module Ribbon
Option ExplicitPublic Rib As IRibbonUIPublic MyTag As String'Callback for customUI.onLoadPublic Sub RibbonOnLoad(ribbon As IRibbonUI) Set Rib = ribbonEnd SubSub GetVisible(control As IRibbonControl, ByRef visible) If MyTag = "show" Then visible = True Else If control.Tag Like MyTag Then visible = True Else visible = False End If End IfEnd SubSub RefreshRibbon(Tag As String) MyTag = Tag 'If Rib Is Nothing Then ' MsgBox "Error, reinicia Excel" 'Else Rib.Invalidate 'End IfEnd Sub
Sub ShowAllButtons()'Show All Call RefreshRibbon(Tag:="*")End SubSub HideButtons()'Hide all with a Tag that start with "LG" Call RefreshRibbon(Tag:="Login")End SubSub Oculta(control As IRibbonControl)Call HideButtonsEnd Sub
All works fine when I start Excel, the addin is loaded, the custom "test Tab" is showed, once the login is completed three additional buttons are showed, my problem is that after I press button "Generar" or "Dudas/comentarios" the macro assigned to these run OK and when I press the "Salir" button to hide the buttons but I received the notification that something went wrong (Runtime error 91: Object variable or with block variable not set), I've reviewed and looking for information but I have not find nothing related.
Many thanks in advance for your help.
VBAMicrosoft ExcelXML
Last Comment
Leonel Garcia
8/22/2022 - Mon
DrTribos
Google for Greg Maxey (MS Word) or Ron de Bruin (MS Excel) both have great examples for custom Ribbons
Hi ste5an many thanks for your answer, I've reviewed it and definitely is a better approach, I've set this part as follows:
Public Sub RibbonGetVisible(AControl As IRibbonControl, ByRef AVisible) On Local Error Resume Next ' Here you can check preconditions (m_Tag) for each button. Select Case AControl.ID Case Is = "grpGenerarBpr" AVisible = False Case Is = "grpNote" AVisible = False Case Is = "grpExit" AVisible = False Case Else AVisible = False End SelectEnd Sub
In this way when file opens I only can see login group as I need, my doubt is how can I proceed in order to show the three groups (grpGenerarBpr, grpNote and grpExit) once the macro assigned to button btnLogIn finishes?.
In response to your recently deleted post, I probably misinterpreted - looked like you were suggesting that the Ribbon XML could be replaced with VBA....
Clean up this <XML> with <VBA>; i.e. I thought replace this <XML> with <VBA>. Which, obviously is not what you meant. Guessing the 'with' should have been an 'and'.
Many thanks, the direction and clarity of the answer help me to achieve the objective, all works great an now I've learned many new things, many thanks again