Show hide objects with Excel VBA – How-to video

Show hide objects with Excel VBA - How-to video - Techronology

This video tutorial displays how to show hide objects with Excel VBA. If you ever thought about game design in Excel, then you may find this lesson interesting.

Overview

Today, you can do a lot of stuff in Excel without coding. But, sometimes you still need to put code on it, allowing you more control of the program. So, we use the Donut Maker app to create a circular object. After that, we use VBA to provide code for click events for two buttons.

Video on how to show hide objects with Excel VBA

Below is the silent video displaying how to make objects appear and disappear with Excel VBA. Overall, it only takes a small amount of code.

YouTube video on how to make objects appear or disappear with Excel VBA.

The code

' hide_All_Faces
'   Hides all the faces in the game
Sub hide_All_Faces()
    For i = 1 To 4
        ActiveSheet.Shapes.Range("shp_Face_" & i).Visible = msoFalse
    Next
End Sub
' show_All_Faces
'   Shows all the faces in the game
Sub show_All_Faces()
    For i = 1 To 4
        ActiveSheet.Shapes.Range("shp_Face_" & i).Visible = msoTrue
    Next
End Sub

Remember from the video, we have four objects, with the names: shp_Face_1, shp_Face_2, shp_Face_3, and shp_Face_4. This way, we can use a For…Next statement to show or hide each one individually. See lines 5 and 13.

One thing we did not try is selecting all four pieces, and also give it a name as a group. Then, you could use one line of code to show or hide all objects. We have to see if that is possible. Of course, you still keep the names of the individual pieces.

Related


Thank you for viewing this how-to lesson. If you want more training, then click on the button below.

How-to guides


Techronology home