Consulting

Results 1 to 5 of 5

Thread: Solved: Hiding/unhiding Command buttons?

  1. #1
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location

    Solved: Hiding/unhiding Command buttons?

    Hi all, i am using the code below to hide command buttons on sheet activate however it will not hide the last clicked button, is it something to do with removing the focus? Here's the code:
    [VBA]
    Private Sub Worksheet_Activate()
    Dim i As Integer
    Dim ib As Integer
    ActiveSheet.Rows("6:6").Hidden = False
    For i = 1 To 6'i used 2 to 6 but changed to 1 to try to cure the problem
    With ActiveSheet.Shapes("CommandButton" & i)
    .Visible = False
    End With
    Next i
    ActiveSheet.Shapes("CommandButton1").Visible = True
    For ib = 1 To 4
    With ActiveSheet.Shapes("Combobox" & ib)
    .Visible = True
    End With
    Next ib
    End Sub
    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  2. #2
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I suspect you'll find that's not actually the button (which is invisible) but is the image of the button - can you click on it?
    Have you tried using Forms toolbar buttons instead, if that's an option?

    Edit: actually, I think you can click on it if you do so without clicking anywhere else first; thereafter it's just a 'ghost'
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You could also set the TakeFocusOnClick property to False for all of them, but I'd still use the Forms versions if possible.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Thanks for the reply Rory, the TakeFocusOnClick was the one, i understand about the forms buttons but i'm lazy and have already coded all my buttons, placed them, sized them and edited them....so too much trouble for a lazy bloke!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I fully understand!
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •