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
|