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
 
 
 
 
 
TitleUse a Word server to print Word files
DescriptionThis example shows how to use a Word server to print Word files in Visual Basic 6.
KeywordsOffice, Word, print, PrintOut
CategoriesOffice
 
Open a Word server object. Use it to open and print the file.

Note that this project contains a reference to the Word object library. You may need to use a different reference for your version of Word.

 
Private Sub cmdPrint_Click()
Dim word_server As Word.Application

    ' Open the Word server.
    On Error GoTo OpenServerError
    Set word_server = New Word.Application
    On Error GoTo 0

    ' Open the file.
    word_server.Documents.Open _
        FileName:=txtFilename.Text, _
        ConfirmConversions:=False, _
        ReadOnly:=True, _
        AddToRecentFiles:=False, _
        PasswordDocument:="", _
        PasswordTemplate:="", _
        Revert:=False, _
        WritePasswordDocument:="", _
        WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto

    ' Print the document.
    word_server.ActiveDocument.PrintOut _
        Range:=wdPrintAllDocument, _
        Item:=wdPrintDocumentContent, _
        Copies:=1, _
        Background:=False

    ' Close the document.
    word_server.ActiveDocument.Close SaveChanges:=False

    ' Close the Word server.
    word_server.Quit False
    Set word_server = Nothing

    MsgBox "OK"
    Exit Sub

OpenServerError:
    MsgBox "Error " & Format$(Err.Number) & " opening " & _
        "Word.Basic" & vbCrLf & Err.Description, _
        vbExclamation, "Error"
    MousePointer = vbDefault
    Exit Sub
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated