Is it possible to hide and show buttons?

G

Guest

I have four buttons on my spreadsheet. (Top of Page, Update, Undo Update,
Redo Update). I was wondering if there was a way to hide the Undo Update
when the spread sheet is opened until the update button is pressed. And hide
the Redo Button untill the Undo button is pressed.)
 
G

Guest

The buttons have a visible property. You would need to run code to set that
property to false. So, the the update click event would contain code to make
the Undo Update visible as an example.

The worksheet/workbook have other events that could come into play.
 
G

Guest

I can't find a visible property How would I go about finding it and changing
it with a code?
 
G

Guest

You can't find it because it is inherited from the container - the Ole Object
(assuming these are on a worksheet).

so from the immediate window as a demo:

? Activesheet.Commandbutton1.Visible
True
activesheet.Commandbutton1.Visible = False

? Activesheet.Commandbutton1.Visible
False

Or you can do

Activesheet.OleObjects("Commandbutton1").Visible = False

Again, from the immediate window as a demo:
Activesheet.OleObjects("Commandbutton1").Visible = True
? Activesheet.Commandbutton1.Visible
True
 
G

Guest

Neither way seems to be working I just get the debug message. Do I need to
change the Commandbutton1 to something else?
 
G

Guest

Commandbutton1 was the name of my button and was used as an example.

You would use the names of your buttons.
 
G

Guest

I named it and its still going to the debug screen no matter what event I
call it from.
 
G

Guest

Are the buttons from the control toolbox toolbar? I demonstrated that the
code works for a commandbutton from the control toolbox toolbar. If your
having problems as you claim, there is little I can say based on the minimal
information provided.
 
G

Guest

Yes, I created them from the control toolbar.
I decided to try it this way but the code still errors
_______________________________________
'Hide Undo Button
Sub HideButtonUndo()

Dim Button_Name As String

Button_Name = "Undo"

With ActiveSheet.Buttons(Button_Name)
If Range("b1").Value = "1" Then
.Visible = True
Else
.Visble = False
End If
End With

End Sub
___________________________________________
Then I just called from the Save Command
Along with adjusting the other cells in other events. the .visible is
getting highlighted.
 
D

Dave Peterson

This code is written for buttons from the Forms toolbar.

If you rightclick on the the button (or commandbutton), do you see an option to
Assign macro?

If you do, then the button is from the Forms toolbar.

If you don't, then the commandbutton is from the Control toolbox toolbar.

And while the button/commandbutton is selected, look at the namebox (to the left
of the formula bar). What do you see?

It's the name of the button/commandbutton.
 
G

Guest

I found this somewhere and I think with a as long as I'm carful where I call
it from it should work more easily than what I was thinking
___________________
Sub ToggleButton()
With Worksheets(1).Shapes("CommandButton1")
If .Visible = False Then
..Visible = True
Else
..Visible = False
End If
End With
End Sub
__________________________
(just changin the sub name, and module name to reflect the button it
toggles, 1 is the worksheet number, and "commandbutton1" to button name.
Thanks for the help I wouldn't of known where to start from with out you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top