Top Banner
How to get started with Excel VBA
21

How to get started with Excel VBA

Feb 15, 2016

Download

Documents

kioko

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 - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: How to get started with Excel VBA

How to get started with Excel VBA

Page 2: How to get started with Excel VBA

We need to enable programming in Excelthe “Developer menu”

Page 3: How to get started with Excel VBA

Objectives 1) To understand the components of the VBA interface 2) Understand the difference between objects and properties3) To use these principles to effect changes in the behaviour of chosen objects4) To be able to get objects to move around the screen

Page 4: How to get started with Excel VBA

Make sure the Developer is ticked

Page 5: How to get started with Excel VBA

Go to DeveloperVisual Basic

Page 6: How to get started with Excel VBA

Programming window opens up, right click on Sheet1 and choose “Insert Form”

Page 7: How to get started with Excel VBA

Like so

Page 8: How to get started with Excel VBA

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

Page 9: How to get started with Excel VBA

Click view toolbox insert image

Page 10: How to get started with Excel VBA

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

Page 11: How to get started with Excel VBA

Insert another image box and import the picture of the other light bulb which is switched on

Page 12: How to get started with Excel VBA

Drag out a command button and call CmdLightoff and write turn me off for the caption

Page 13: How to get started with Excel VBA

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

Page 14: How to get started with Excel VBA

Add the following code

Make the imglightoff visible

Make the imglighton visible

Page 15: How to get started with Excel VBA

Draw out a label at the top of the form and call it lblmessage, leave the caption blank

Page 16: How to get started with Excel VBA

Add the following code lblmessage.Caption = “turn me off now” in the Cmdlightson_Click button and run the program and

Page 17: How to get started with Excel VBA

Press Turn me off and Turn me on

Page 18: How to get started with Excel VBA

The following should be displayed

Page 19: How to get started with Excel VBA

Try adding this to change the background colour of the image

Page 20: How to get started with Excel VBA
Page 21: How to get started with Excel VBA

Extension Activities

1) 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

2) 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

3) See if you can use the backcolour of the lightbulb when the light is turned out 4) 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 5) What can be done to improve the program?