borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How to print a spreadsheet using VB?)Next Topic (printing a form to the fullest of a4 size paper) New Topic New Poll Post Reply
AndreaVB Forum : Printing : I need to print a word document in VB properly
Poster Message
andycharger
Level: Guest


icon 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

18-03-2003 at 04:37 PM
| Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: I need to print a word document in VB properly

I had something like this a while back, try changing the background setting to false.

Cheers Steve

23-04-2003 at 10:47 AM
View Profile Send Email to User Show All Posts | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: I need to print a word document in VB properly

if steve_w's idea doesn't work, although it probably will do. The problem may be that word is not set to spool to the printer queue instead of waiting for the printer to finishing, if this is the case it should be nothing to worry about as it is set as default on most computers.

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

23-04-2003 at 12:23 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Printing : I need to print a word document in VB properly
Previous Topic (How to print a spreadsheet using VB?)Next Topic (printing a form to the fullest of a4 size paper) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder