1. The life of era
Visual Basic 6.0
Create a data from Visual Basic and print an output to MS Word.
Written and Designed by
Mark John P. Lado
No part of this book may reproduce without written consent from the author. By using this
book you agree not to use this for any purpose that is illegal. You agree not to alter, modify,
or cause the alteration or modification, of the book, without prior written consent from the
author.
2. ACKNOWLEDGEMENT
First and foremost to our Almighty God for giving me strength every day for the guidance
and good health, for the graces and blessings that help me in making the project possible.
And most of all to my parents and guardians, thank you for showing your unconditional love
and unending support financially and spiritually.
3. INTRODUCTION
The book contains programming codes which is written in VB6 or the Visual Basic 6.
In this book, you will learn on how to create a simple program, print a data from visual basic
to Microsoft Word and other basic procedures. This is a beta version only where the reader
can get some ideas in performing the project. This Book contains screen shots of the actual
program and their respective source code.
5. Show Form
To show another form from the current form you need to use command button and add it
to your current form.
And create another form where when you click the command button the next form will
show up.
Then double click the command button then write the codes and then run.
Private Sub Command1_Click()
Form1.Hide
Form2.Show
End Sub
6. Print data using ms word.
In this section you need to add labels, text boxes and one command button for print.
Rename it.
7. The label1 is for name, label2 is for age, label3 is for address. The textboxes is the same as
label but not the same function. Just remove the text of textboxes. Change also the caption
of command button into Print.
After making the interface, open an empty Microsoft word and create your template so that
when you click the print button from your vb6 you will be directed to ms word.
8. In your word, go to developer’s ribbon. And add text form, same format as you did in your
vb6 program.
9. As you see there is and dark boxes. Right click on it and go to properties. In the bookmark
rename the default text1 into w_name, do this to the age and address. And after editing
save it as template and put it where your visual basic program located.
10. Go back to your program.
Double click the print button and write the codes. Observe properly.
Private Sub Command1_Click()
Static wd1 As Word.Application
Static wd1Doc As Word.Document
Set wd1 = New Word.Application
wd1.Visible = True
Set wd1Doc = wd1.Documents.Add(App.Path & "mytemplate.dot")
With wd1Doc
.FormFields("w_name").Range = Text1.Text
.FormFields("w_age").Range = Text2.Text
.FormFields("w_address").Range = Text3.Text
End With
Set wd1 = Nothing
Set wd1Doc = Nothing
End Sub
11. Setting references
Set ms word references so that you can connect. Find the Microsoft Word 12 Object Library
and check. And save your project where your template was.
Test your program.