Help with Printing from a VB6 App

J

Jonathan West

Hi Félix

This is the problem line

moWordApp.ActiveDocument.PrintOut Background:=True,
Range:=wdPrintCurrentPage, Item:=wdPrintDocumentContent

Change Background:=True to Background:=False

The problem is that Word is getting closed before the background print is
given a chance to complete.

Take a look here for more on the issue

How to find out whether Word has finished printing
http://www.mvps.org/word/FAQs/MacrosVBA/WaitForPrint.htm

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
F

Félix Meléndez

Hi there,

I developed (in VB6 SP5) a class wrapper that one of its functionality is to
print a document. When I run the code in debug mode, and stop at the line
that prints the document, everything works fine. But, when I let it execute
without stopping it, the document does not get printed.

I have the following code:

Public Sub Process(ByRef boolRetCode As Boolean, _
ByRef strRetMessage As String)

Dim boolDocIsClosed As Boolean

boolRetCode = True
strRetMessage = vbNullString
boolDocIsClosed = True

On Error GoTo Process_Err
Set moWordApp = New Word.Application

' Make it visible?
moWordApp.Visible = mboolMakeWordVisible
If moWordApp.Visible Then
moWordApp.WindowState = wdWindowStateMinimize
End If

Set moWordDoc = moWordApp.Documents.Add
boolDocIsClosed = False
With moWordApp
With .Selection
...
...
.TypeText "Nosotros, ENRIQUE SALVO MENDIETA, soltero, Administrador
de Empresas y "
...
...

End With

WHEN I GET TO THIS FOLLOWING LINE:
WHEN I ENTER DEBUG MODE AND STOP (F9) AND THEN RESUME (F8) THE PRINTING
GOES WELL
IF I DON'T ENTER DEBUG MODE AND LET THE PROGRAM EXECUTE BY ITSELF THE
DOCUMENT DOESN'T GET PRINTED!

' Print document
moWordApp.ActiveDocument.PrintOut Background:=True,
Range:=wdPrintCurrentPage, Item:=wdPrintDocumentContent

Process_Exit:

If Not boolDocIsClosed Then
' Close Active Document
moWordDoc.Close wdDoNotSaveChanges
' Close Word
moWordApp.Quit
' Close instance
Set moWordApp = Nothing
End If
Exit Sub

Process_Err:
boolRetCode = False
strRetMessage = Err.Description

Resume Process_Exit
End Sub


Please, Can someone give me a hint on this?

Thanks in advance,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top