Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a Word document in Visual Basic 6
DescriptionThis example shows how to make a Word document in Visual Basic 6.
KeywordsWord, office, word document
CategoriesOffice, Files and Directories
 
Note: Add a reference to Microsoft Word 9.0 Object Library.

The MakeWordDoc subroutine creates a Word server and uses its Documents.Add method to make a new document. It uses the Selection object's methods to write text into the document, saves the document, and then closes the document and the Word server.

 
Private Sub MakeWordDoc(ByVal file_name As String, ByVal _
    title As String, ByVal body As String)
Dim word_app As Word.Application
Dim word_doc As Word.Document

    ' Open Word and create a document.
    Set word_app = New Word.Application
    Set word_doc = _
        word_app.Documents.Add(DocumentType:=wdNewBlankDocument)
    
    ' Write the title.
    word_app.Selection.TypeText title
    word_app.Selection.Style = _
        ActiveDocument.Styles("Heading 1")
    word_app.Selection.TypeParagraph

    ' Write the body.
    word_app.Selection.TypeText body

    ' Save the file.
    word_doc.SaveAs FileName:=file_name

    ' Close the document and Word.
    word_doc.Close False
    word_app.Quit False
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated