|
ActiveX technologies which has
been build upon COM, DCOM and OLE has brought a lot power to
Visual Basic programming. Based on these technologies,
Visual Basic is able to create applications for other MS
Windows programs like MS Words, MS Excel, MS Access and etc.
I have already illustrated how we can build Excel
Applications using VB, here I will show you how to build
word application. In order to write text to a MS Word
document, you need to add a reference to the Microsoft Word
11.0 Object Library from the project menu.
The statement Dim MyWord As Word.Application
creates a reference to MS Word so that we can control MS
Word through automation.
The statement
MyWord.Documents.Add add a document to the Documents
Collection Word . The following statements
MyWord.Selection.Shading.Texture
= wdTexture15Percent
MyWord.Selection.Font.Size = 20
Format the text of the document.
And finally teh statement
MyWordDocuments(1).SaveAs ("D:\sample1.doc")
Save the document as
sample1.doc. You can open this file using MS Word. |
Option Explicit
Dim MyWord As Word.Application
Private Sub Form_Initialize()
Set MyWord= New Word.Application
End Sub
Private Sub cmdSave_Click()
cmdSave.Enabled = False
MyWord.Documents.Add
MyWord.Selection.Shading.Texture = wdTexture15Percent
MyWord.Selection.Font.Size = 20
mWord.Selection.TypeText (TxtEditor.Text)
MyWordDocuments(1).SaveAs ("D:\sample1.doc")
MyWordQuit
End Sub
|