Combine two buttons in one and change the text.

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
380
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I use the below 2 sets of code to hide and unhide the commandbars and some other stuff. I would like to let this work behind one button and when let the text on the button change when you push it. Is that possible?
Thank you for your time.

Romano


VBA Code:
ActiveSheet.Unprotect "trein"


Dim cb As CommandBar
  For Each cb In CommandBars
    If cb.Type < 3 Then cb.Enabled = False
  Next cb
  With ActiveWindow
    .DisplayHeadings = False
    .DisplayWorkbookTabs = False
  End With
  With Application
    .DisplayFullScreen = True
    .DisplayFormulaBar = False
    .DisplayScrollBars = False
    .DisplayStatusBar = False
  End With

    
ActiveSheet.Protect "trein", AllowFiltering:=True
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True

End With


VBA Code:
ActiveSheet.Unprotect "trein"

Dim cb As CommandBar
  For Each cb In CommandBars
    If cb.Type < 3 Then cb.Enabled = False
  Next cb
  With ActiveWindow
    .DisplayHeadings = True
    .DisplayWorkbookTabs = True
  End With
  With Application
    .DisplayFullScreen = False
    .DisplayFormulaBar = True
    .DisplayScrollBars = True
    .DisplayStatusBar = True
  End With

'This will enable all BuiltIn Command bars
Dim Cbar As CommandBar
For Each Cbar In Application.CommandBars
Cbar.Enabled = True
Next
   
ActiveSheet.Protect "trein", AllowFiltering:=True, AllowFormattingColumns:=True
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello Romano,

Simply write a single macro to call each macro based on another cell: then it will toggle between them.

VBA Code:
Sub Combine
If Range("Z1").value = 1 then
Call Macro1Name
Range("Z1").value = 0
Else
Call Macro2Name
Range("Z1").value = 1
End If
End Sub

Jamie
 
Upvote 0
Solution
Hello Romano,

I didn't read the bit about the name changing on the button. :(
Select the shape and in the formula bar type =Z2
Then in cell Z2 type the formula:- =if(Z1=1,"On","Off")

Change Z1 / Z2 / On / Off to what you would like.

Jamie
 
Upvote 0
Hello Romano,

I didn't read the bit about the name changing on the button. :(
Select the shape and in the formula bar type =Z2
Then in cell Z2 type the formula:- =if(Z1=1,"On","Off")

Change Z1 / Z2 / On / Off to what you would like.

Jamie
Thank you, that helped a lot. Have a nice day.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top