210 likes | 346 Views
How to get started with Excel VBA. We need to enable programming in Excel the “Developer menu”. Objectives . 1) To understand the components of the VBA interface 2) Understand the difference between objects and properties
E N D
Objectives 1) To understand the components of the VBA interface 2) Understand the difference between objects and properties 3) To use these principles to effect changes in the behaviour of chosen objects 4) To be able to get objects to move around the screen
Programming window opens up, right click on Sheet1 and choose “Insert Form”
Ensure that you save your work as an excel macro enabled workbook at this stage otherwise you will not be able to access your work again in VB
Rename the image box Imglightsoff and import the picture of the light bulb which is off The border style property should be set to 0
Insert another image box and import the picture of the other light bulb which is switched on
Drag out a command button and call CmdLightoff and write turn me off for the caption
Add another command button and call it Cmdlighton and add turn me on for the caption. Double click on the command button should take you to the code window
Make the imglightoff visible Make the imglighton visible Add the following code
Draw out a label at the top of the form and call it lblmessage, leave the caption blank
Add the following code lblmessage.Caption = “turn me off now” in the Cmdlightson_Click button and run the program and
Try adding this to change the background colour of the image
Extension Activities Change the caption on the label when the light is switched on to read for the on the light “Hello World, you have turned me on” See you can change the back colour on the label to yellow using lblmessage.backcolor = vbyellow Change the caption on the label to read “Goodbye world you have turned me off” See if you can change the background colour of the label to white See if you can use the backcolour of the lightbulb when the light is turned out See if you can change the caption that appears on the command button to cmdlighton.caption to “don’t forget to turn me off when you are finished What can be done to improve the program?