0

I have .xlsb file with user ribbon (i made it in "Custom UI Editor For Microsoft Office"). enter image description here

I want automatically delete (or hide) this ribbon from file (with VBA). Is it possible?

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
Alexey C
  • 172
  • 6
  • Have you tried recording a macro of the manual removal process? – Daghan Dec 19 '19 at 07:36
  • How to remove it manually? I can remove it, when edit XML structure of xlsb file with Custom UI Editor. I don't know how to remove it with excel-tools. – Alexey C Dec 19 '19 at 07:37
  • Does the ribbon show in the tabs menu if you right-click the ribbon click customize? – Daghan Dec 19 '19 at 07:53
  • No. If i select "All tabs", there are no my ribbon too – Alexey C Dec 19 '19 at 07:54
  • Does this answer your question? [Excel Hide/Show all tabs on Ribbon except custom tab](https://stackoverflow.com/questions/19967283/excel-hide-show-all-tabs-on-ribbon-except-custom-tab). Or to put it shortly: What you want to do is not possible with VBA. – Storax Dec 19 '19 at 08:24
  • Thank you, it's very sad. You can post it like an answer and i will mark it. – Alexey C Dec 19 '19 at 08:37
  • It is not true. You can Hide a custom tab using VBA – Siddharth Rout Dec 19 '19 at 08:47
  • @Siddharth: Ah, ok, would be nice if you could post how to do it. Or maybe I got the question wrong. – Storax Dec 19 '19 at 08:50
  • It is slightly complex. Let me create an sample file and explain it with that. gimme an hours time. I am in the office... – Siddharth Rout Dec 19 '19 at 08:51
  • Are you talking about [this](https://learn.microsoft.com/en-us/previous-versions/office/developer/officetalk2007/ee390805(v=office.11)?redirectedfrom=MSDN) resp. [this](https://www.rondebruin.nl/win/s2/win012.htm). Thanks for correcting me. It is indeed possible to hide a custom tab as well. I only knew how to use getvisible for elements on the tab. – Storax Dec 19 '19 at 08:52
  • I managed to get some time so I created a sample. One moment, posting an answer – Siddharth Rout Dec 19 '19 at 09:12
  • @Storax: Just visited those links.. yes you are right. – Siddharth Rout Dec 19 '19 at 09:25
  • Your question 6 months ago was different. I answered it accordingly. For your new requirement, you need to ask a new quesiton. Please do nto edit the question to completely change the requirement after 6 months :) – Siddharth Rout Jun 03 '20 at 21:42
  • I have rolled back the changes that you made. Please ask a new quesiton. Feel free to link this question in your new quesiton. – Siddharth Rout Jun 03 '20 at 21:43

1 Answers1

2

For this demonstration, you need CustomUI Editor and Excel(Obviously)

Create a new workbook and save it as say AlexExample.xlsm

[A] Open VBE, and insert a module. Paste this code in the module

Option Explicit

Dim Ribn As IRibbonUI
Public RibnTag As String

Sub RibbonOnLoad(ribbon As IRibbonUI)   
    Set Ribn = ribbon
End Sub

Sub GetVisible(control As IRibbonControl, ByRef visible)
    Select Case RibnTag
    Case "ShowTab": visible = True
    Case "HideTab": visible = False
    End Select
End Sub

Sub ShowMyRibbonTab()
    RibnTag = "ShowTab"
    If Not Ribn Is Nothing Then
        Ribn.Invalidate
    Else
        MsgBox "Couldn't get the ribbon object. Please close and restart the workbook"
    End If
End Sub

Sub HideMyRibbonTab()
    RibnTag = "HideTab"
    If Not Ribn Is Nothing Then
        Ribn.Invalidate
    Else
        MsgBox "Couldn't get the ribbon object. Please close and restart the workbook"
    End If
End Sub

[B] Open the ThisWorkbook code area and paste this code

Option Explicit

Private Sub Workbook_Open()
    RibnTag = "ShowTab"
End Sub

[C] Go to the sheet and create 2 buttons (Form Control). SHOW and HIDE as shown below. Right click on the button and assign the macro ShowMyRibbonTab to SHOW and HideMyRibbonTab to HIDE

enter image description here

[D] Next Open CustomUI Editor and open the Excel File from there. Insert customUI.xml and paste the below code there.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI onLoad="RibbonOnLoad" 
xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
    <tabs>
      <tab id="MyCustomTab" label="AlexsTab" getVisible="GetVisible" tag="AlexsTab" >
    </tab>
</tabs>
</ribbon>
</customUI>

Save and close the file and you are done.

SAMPLE FILE: https://www.dropbox.com/s/izzbwpcmqtyoibd/AlexExample.xlsm?dl=0

enter image description here

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • Thank your for your comment, it works very good. But it does not resolve my problem. I have .xlsb file with my ribbon and macroses. Then i want to clear it from macroses and hide ribbon (i need to share this file w/o my information). Easiest way to clear it from macro is hide ribbon and save it in .xlsx format, but when i reopened this xlsx file i have alert with error (Cannot run the macro "RibbonOnLoad", because macroses is cleared). Any advices? – Alexey C Jun 03 '20 at 14:06
  • Your question 6 months ago was different. I answered it accordingly. For your new requirement, you need to ask a new quesiton. Please do nto edit the question to completely change the requirement after 6 months :) – Siddharth Rout Jun 03 '20 at 21:42