1. Home
  2. Computing & Technology
  3. Visual Basic
VBA - The Word Working Partner
The Automated Tutorial Review Program
 More of this Feature
• Part 1: Using VBA with Microsoft Word
• Part 2: Automate Your Letter Writing
• Part 3: The AboutVBA.DOC Code Sample
• Part 4: Word Objects
• Part 6: Using Toolbox Components
 
 Join the Discussion
Create a brilliant VBA app?
Tell Us About It!
 
 Related Resources
• Segment One of the VBA Tutorial
• The About Visual Basic Subjects List
• Beginning Visual Basic
• Visual Basic 6
 
 From Other Guides
• About Desktop Publishing for MS Word
• About Business Software
 
 Elsewhere on the Web
• MS: Word Objects
• MS: Templates vs Add-In's
 

We're going to automate the complete process of building a review for this tutorial by building on the example just shown. Icons will be added to the standard toolbar to call the VBA programs and a few more programs will be written.

First, add an icon that calls your VBA program to the standard toolbar by following these steps:

  1. Left-click the toolbar and select customize
  2. Scroll down and select Macros in the Categories list box
  3. Select the WordArt VBA program from the list
    (It's identified as Project.NewMacros.WordArt on my system. It might have a slightly different name on yours depending on the names you used.)
  4. Click and drag the entire Command and drop it where you want it to be on the toolbar. Notice that an "I-beam" cursor appears in the toolbar where it will be positioned.
  5. Click Modify Selection to display a button image and change the button image. I used a "happy face" -- a standard image. Notice that you can edit the image with a built in icon editor.

To continue my automated "Tutorial Rating System" I programmed a "RateIt" VBA Program that looks at the character just to the left of the text cursor and assigns a text rating if the character is from 1 to 5. Notice that this program is almost completely "traditional" Visual Basic. Here's that program:

Sub RateIt()
Selection.MoveLeft _
    Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Select Case Selection.Text
Case "1"
    Selection.Text = _
    "Huzza! Great! Loving It!"
Case "2"
    Selection.Text = _
    "Not the most wonderful but still quite good."
Case "3"
    Selection.Text = _
    "It's OK I guess. Seen better and seen worse."
Case "4"
    Selection.Text = _
    "It's a start but it needs work."
Case "5"
    Selection.Text = _
    "What a pile of GARBAGE!"
Case Else
    Selection.Text = _
    "Must be a number from 1 to 5. Try again."
End Select
End Sub

This program was assigned to a button on the tool bar as well.

Next page > Using Toolbox Components > Page 1, 2, 3, 4, 5, 6
Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.