andycharger Level: Guest

|
I need to print a word document in VB properly
Hi,
I am having all sorts of problems printing from VB.
I can get my document to open, swap values on my document for variables in vb and print it. The problem occurs when I try to close the document afterwards. The system warns me there are jobs in the print queue and closing word will cancel the print jobs. I want to make sure I have printed before I close word.
If I do close word, When I try and print the form again, I get an error telling me that the remote server machine does not exist or is unavailable.
Please help.
Here is all my code
Private Sub Command2_Click()
Dim oWord As New Word.Application
Dim oDoc As New Word.Document
Set oDoc = oWord.Documents.Add("c:irsirsquote.doc")
'Dim Worddoc As New Word.Application
' Open Word with your template
'Worddoc.Documents.Add ("c:irsirsquote.doc")
With oDoc
'worddoc.ActiveDocument
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "yourfield1"
.Replacement.Text = (lblQuoteNumber)
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End With
oDoc.Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
'oDoc.Close savechanges:=False
Set oDoc = Nothing
oWord.Quit
End Sub
|