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.
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.
' Hides all the faces in the game
For i = 1 To 4
ActiveSheet.Shapes.Range("shp_Face_" & i).Visible = msoFalse
' Shows all the faces in the game
For i = 1 To 4
ActiveSheet.Shapes.Range("shp_Face_" & i).Visible = msoTrue
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.
Thank you for viewing this how-to lesson. If you want more training, then click on the button below.