1 / 21

How to get started with Excel VBA

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

kioko
Download Presentation

How to get started with Excel VBA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to get started with Excel VBA

  2. We need to enable programming in Excelthe “Developer menu”

  3. 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

  4. Make sure the Developer is ticked

  5. Go to DeveloperVisual Basic

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

  7. Like so

  8. 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

  9. Click view toolbox insert image

  10. 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

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

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

  13. 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

  14. Make the imglightoff visible Make the imglighton visible Add the following code

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

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

  17. Press Turn me off and Turn me on

  18. The following should be displayed

  19. Try adding this to change the background colour of the image

  20. 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?

More Related