Hiding and unhiding buttons in "add ins" on ribbon

Richard U

Active Member
Joined
Feb 14, 2006
Messages
383
Office Version
  1. 365
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
I've used the commandbar to create and remove buttons....

Code:
Sub AddNewCB()
   Dim myCommandBar As CommandBar, myCommandBarCtl As CommandBarControl
   On Error GoTo AddNewCB_Err
   Set myCommandBar = CommandBars.Add(Name:="MY_LIST", Position:=msoBarFloating, MenuBar:=False, Temporary:=True)
   myCommandBar.Visible = True

   Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
   With myCommandBarCtl
      .Style = msoButtonCaption
      .Caption = "Load File  "
      .OnAction = "'LoadFile'"
   End With
   Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
   With myCommandBarCtl
      .Style = msoButtonCaption
      .Caption = "Make ABC   "
      .OnAction = "'Make_ABC"
   End With
   Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
   With myCommandBarCtl
      .Style = msoButtonCaption
      .Caption = "Make DEF  "
      .OnAction = "'Make_DEF'"
   End With
   Exit Sub

   Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
   With myCommandBarCtl
      .Style = msoButtonCaption
      .Caption = "Export file"
      .OnAction = "Export_File"
   End With
   Exit Sub


AddNewCB_Err:
   Debug.Print Err.Number & vbCr & Err.Description
   Exit Sub
End Sub


Sub RemoveToolbar()
    Dim myCommandBar As CommandBar
    For Each myCommandBar In Application.CommandBars
        If myCommandBar.Name = "LOAD_LIST" Then
            myCommandBar.Delete
            Exit For
        End If
    Next
End Sub


What I want to do is hide buttons as they don't apply. I don't want "Export file" to be visible until I make either ABC or DEF, and after I pick ABC or DEF, I want to hide the one that I don't pick.

How can I do this

(I HATE THIS @#$@^**!!! RIBBON)
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Watch MrExcel Video

Forum statistics

Threads
1,109,334
Messages
5,528,093
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top