| 
            
           | 
          
            | 
          
          
          
          
            
              
              
                
                  | Title | Make a Word document in Visual Basic 6 |  
                  | Description | This example shows how to make a Word document in Visual Basic 6. |  
                  | Keywords | Word, office, word document |  
                  | Categories | Office, 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
               |  
              
              
              
              |   |  
               
 |  
              |   |  
              
           |  
          
          
          
          
             
           |