Position: Home > Blog Center > Project Solutions > 2011 > 2011/08 > 2011/08/08 > Programming with word: write Visual Basic programs using MS Word
Low Cost Custom Prototype PCB Manufacturer

Project Solutions

Programming with word: write Visual Basic programs using MS Word

Published:2011/8/8 22:02:00 Author:Li xiao na From:SeekIC

By T. Fondrat

Not many PC users are aware that the well-known Microsoft Word includes a programming environment for Visual Basic. It allows you to get to grips with the fundamentals of this programming language.

This article will be of particular interest to those of you who don’t have the complete Visual Basic package, but who would still like to play with a programming language under Windows. The trick here is: use Visual Basic for Applications. which is available in Word as well as Excel.

Step1

Stan Word All the screen dumps and programs shown here were made using Word 2000. but other versions such as Word 97 work just as well!

Step 2

From the View menu click on Toolbars. Then select Visual Basic, as shown in figure 1.

Figure 1

Step 3
The Visual Basic toolbar appears (figures 2 and 3).

figure2 and figure 3

Step 4

Now we’ll make a button called Command Button (figure 4). To look at a list of the properties of the button you have to position the mouse cursor over the button, then right-click on it and select Properties.

figure 4

A new window pops up containing all the properties of the object (figure 5).The two most important properties are name and caption. Give a name to the button, which in our example is Button Test Message.

figure 5

Replace the text on the button with Click on this button!. You can also change other settings, such as the size. font. background color, background picture, etc.

As an aside. Visual Basic has many windows that are clearly laid out. or not! That is left to die user, but try not to get confused by all those open windows.
Step 5

Double-click on the button.

The Visual Basic editor opens. The procedure ButtonTeslMessage_Click is created, if it didn’t exist already, and the cursor appears HERE, where you will write your program (figure 6)!

figure 6

This procedure is run with every click on the Button-Test Message button.

Or more precisely, the procedure Click is linked to the object Button Test Message. of type Command Button (also described as: belongs to the Command Button class). The code for this procedure is entered here.

Step 6

Enter the line: MsgBox ("You’ve clicked here!") (figure 7a).

figure 7a

Step 7

Return to Word, using Alt-Tab for example, and return to Run-mode by deselecting the two icons on the Visual Basic toolbar (figure 7b).

 figure 7b

You can also minimize the Visual Basic toolbar if you want to have a clear desktop, but you will have to enable it again if you want lo continue programming.

Step 8

Save the file in Word format and test how it runs.

Summary

A small program can be written in seconds using MS Word. You should now have an idea of all the possibilities it offers. The same method can also be used in MS Excel to program in Visual Basic: create windows with buttons, input fields for text or data, pictures, etc. Show the information in graphs. personalize the Word menu with user-defined commands, run other programs. It is also possible (although that really needs a separate article) to use API’s under Windows, to program the parallel port for example. Complex programs that hide the standard menus can be written this way. The users will think that they’re running a dedicated program, whereas the reality is that it runs under Word or Excel.



Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/08/08/Programming_with_word__write_Visual_Basic_programs_using_MS_Word_(1).html

Print this Page | Comments | Reading(733)

To evaluate my
Code: