Library code snippets

A quick way to toggle visibility

If you want show something when its hidden, or hide it if its showing you may do this:

If Control1.Visible = True Then
 Control1.Visible = False
ElseIf Control1.Visible = False Then
 Control1.Visible = True
End If


However, a quicker way is to do:

Control1.Visible = Not Control1.Visible

Also, if you have a menu like 'View Toolbar' you can use the resultant visibility to set the checkmark on it. For Example

Private Sub mnuViewToolbar_Click()
  tbToolbar.Visible = Not tbToolbar.Visible
  mnuViewToolbar.Checked = tbToolbar.Visible
End Sub


By the way, if you make the item visible in the first place, make sure the menu is checked by default.

Comments

  1. 11 Oct 2005 at 08:12

    My knowledge of VBA is very poor so I was wondering if someone could advise me how to disable menu items such as those that drop down from the FILE or TOOLS menus or even the whole menu.


    What I would like to happen is that the menu item remains on the drop down list but is greyed out and disabled.


    I hope that this makes sense.

  2. 09 Oct 2001 at 21:40

    I think it would be best to just introduce the not operator and then show its uses(like toggling visibility).

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of A quick way to toggle visibility.

Leave a comment

Sign in or Join us (it's free).