Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”

Similar presentations


Presentation on theme: "How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”"— 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 Insert a command button and call it cmdlights and move the image of the light on to cover the image of the light off

13 Double-click on the form to enter the “code” window. Most things are typed between Sub and End Sub which are created for you by VB

14 Declaring a variable name as Boolean Use the select if to turn the lightbulb on or off, When the lights is true the light bulb is on and when the lights are false the light bulb is turned off End if part Press F5 of the run command to execute the program Changes the caption on the command button

15 Lights off Lights on

16 Activities Try to get the light bulb when it is switched on to move randomly around the screen.

17 Insert the following code, this is called a procedure which only activates when the lights = true statement is true. The command calls this procedure and makes the lightbulb move around the screen

18

19 Add 3 scroll bars from the toolbox call them HSBRED, HSBGREEN and HSBBLUE. Change the maximum value on 255

20 Create a new procedure called sub showformcolour() Generates a random number between 0 and 255 Creates a random number to change the colour background of the form Sets the background colour of the form based on the 3 prime colours

21 Now run the program

22 Extension Activities 1)See if you can randomly change the background colour of each individual colour on the form. 2)Insert a message using a label 3)Insert a message using a msgbox


Download ppt "How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”"

Similar presentations


Ads by Google