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

VBA - The Word Working Partner - Part 2

By Dan Mabbutt, About.com

3 of 4

The Program Code

Macro Icons

Macro Icons

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. The "justice scales" icon was added to the toolbar for this program. 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
~~~~~~~~~~~~~~~~~~~~~~~~~

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
  4. Learn VB 6
  5. Learn VBA
  6. VBA - The Word Working Partner - Part 2

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

All rights reserved.