Tips on Using Visual Basic
Getting into Visual Basic
- Under View, Click toolbars, then Control Toolbox
- In the Control Toolbox, you must click the blue draftsman's
triangle to enter 'Design Mode'
- Click on the icon with the large 'A' (this is the 'Label' icon)
- After clicking once, drag over a rectangular area on the screen
- You will see a caption 'Label1' in the area of the label
- Double-click on this label, and you will have reached Visual Basic
- Whenever the label is clicked, the code you write will be excecuted
The control toolbox
- Lots of controls. We will discuss just a couple
- Label (discussed further below)
- Scroll bar (discussed further below)
- Picture Box (you can place a picture here, and it will show
or not show as you command)
Properties of the Label
- You get to the Properties Menu by right-clicking on the
Label
- Caption: change this to what you want the label to say
- Background: put in the color you want - click on the '...'
at the right and then the Palette tab
- Font: click on the '...' at the right of the menu, then select
the font and size
- Visible: set this to True or False, depending on if the label
is to be seen initially
The scroll bar (slider)
- The scroll bar has an integer value you control via dragging
its bar, or clicking to the righr or left of the bar, or at the ends with
the little triangles
- This integer value is transmitted to a spot on the spreadsheet called
the Linked Cell. You set this using the Properties Menu (see
below)
- The scroll bar icon on the control toolbox is a pair of triangles separated
vertically (but no line between them!)
- Click on the icon, then drag over a rectangular area on the spreadsheet
- Right-click to bring up the Properties Menu
- Select the Linked Cell
- Set the Max value (the default is quite high, 32767)
- Set the Large Change to perhaps 10. This is the increment
when you click to the right or left of the bar
A few things the Visual Basic code will do
- Identify a cell on the spreadsheet
- Get the value of that cell, or change that cell's value
- Make a label visible or invisible
- Execute loops for repetitive operations
- Make pictures visible or invisible
To get out of Design Mode, you must click the Draftsman's triangle again.
Now you can try the stuff you have set up.
Here is a simple demo spreadsheet. I
think you'll see how it works.
Here is the Visual Basic code
underneath the simple demo with copying numbers, squaring them etc.