0% found this document useful (0 votes)
22 views

Visual Basic From Excel or Word

The document describes how to write and run basic Visual Basic programs from within Microsoft Excel or Word using the Visual Basic Editor. It provides step-by-step instructions to create a simple program with a text box and command button that outputs text. It also shares examples of cryptarithm solving programs.

Uploaded by

Hasan Isfahani
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Visual Basic From Excel or Word

The document describes how to write and run basic Visual Basic programs from within Microsoft Excel or Word using the Visual Basic Editor. It provides step-by-step instructions to create a simple program with a text box and command button that outputs text. It also shares examples of cryptarithm solving programs.

Uploaded by

Hasan Isfahani
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

'Copyright 2000 The American Cryptogram Association (ACA)

'3613 Piedmont Drive, Plano TX 75075-6234


'All rights reserved.
How to make and run Visual Basic programs from MS Excel or Word
programs.
Within Word or Excel there is a
tools, for writing Visual Basic
note is aimed at showing how to
possible. It does not aspire to
program in Visual Basic there
that.

Visual Basic Editor, together with


programs and running them. This brief
get started and a little of what is
teach the ins and outs of how to
are plenty of books available on

The Visual Basic Editor is also present in MS Access and Powerpoint.


Part A getting started.
1. Start Excel.
2. On the task bar click Tools\Macro\Visual Basic Editor. You will
get the Visual Basic Editor containing a blank worksheet.
3. On the task bar click on Insert\User Form. You will get a form,
called UserForm1, and a toolbox superimposed on the worksheet. Drag
the toolbox to one side.
4. Click on UserForm1 and drag the lower, right hand corner to make
the form larger.
5. In the toolbox click on the ab icon (the textbox icon) and then
click on UserForm1 a text box is dropped onto the form, and its
name is TextBox1. Move the textbox to the top left corner and then
drag the lower right corner to enlarge it.
6. In the toolbox click on the command button icon (middle of the 2nd
row) and then click on a free part of UserForm1 a command button is
placed there, called CommandButton1.
7. Double click on the command button; you will get a white form, or
code window, with the following brace:
Private Sub CommandButton1_click()
End Sub
Between these two lines we write our program code. As an example:
(a)
Private Sub CommandButton1_click()
Line = Line + Output is
For j = 1 to 10
Line = Line + Str(j)
Next j
TextBox1.Text = Line
(b)

End Sub

Click on the taskbar Run\Run. The program runs and you get
UserForm1 with the textbox and command button.
(c) Click the command button: the program executes and displays in
the textbox the expected
Output is 1 2 3 4 5 6 7 8 9 10

(d) click the x on the top right corner of UserForm1 to stop the
program.
Part B running the Make Values program.
1. Double click on the CommandButton1 to bring up the code window.
Delete the program we have just written in, but leave the braces
there. Paste in, or type in, the program Make Values from the
Crypto Drop Box.
2. On the Task Bar click View\Project Explorer and in the box that
appears click on UserForm1 to get our form back.
3. On the Task Bar click on View\Properties to get a small box called
Properties_TextBox1. In this box
- click MultiLine and choose true
- click Font and a small button will appear on the font line.
Click this button to get a dialogue box, in which choose Courier New
and size 10.
4. Now click Run\Run to run the program and click CommandButton1.
5. The program will create indices for each of the three words
STUBTOES, FOURDOOR and DUOAORBB. Then from the perm 5089721463 the
values of the three words will be calculated. Finally the program
displays all this data as follows:
word(0) = STUBTOES
word(1) = FOURDOOR
word(2) = DUOAORBB
derived alpha=STUBOEFRDA
index(0)=
index(1)=
index(2)=

0 1 2 3 1 4 5 0
6 4 2 7 8 4 4 7
8 2 4 9 4 7 3 3

if perm =

5 0 8 9 7 2 1 4 6 3

value(0) =
value(1) =
value(2) =

50890725
17846774
68737499

Part C running the Make Perms program.


Proceed as described above.
The program will display all the perms for 5 digits. Perms for a
different number of digits (say 8) can be displayed by changing the
6th line in the program to
length = 8
To solve an addition cryptarithm this program would be combined with
the Make Values program and the display section adjusted to show
the solution rather than all the perms.
Part D conclusion.
I am indebted to photon for pointing out to me that Word and Excel
contain this hidden nugget of Visual basic.
This little introduction is to help you get started. Computer solving
programs, such as BION and I describe in our columns, are just one
type to work on. Equally rewarding are interactive programs that take

the labour out of pencil and paper work, and leave you to solve with
your own initiative rather than the computers muscle. photon is an
arch-exponent of this art.
Help is available from the Visual Basic Editor taskbar, from the MS
Visual Basic web site and from numerous manuals.

You might also like