Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word 2000 OLE code only prints one .DOC no others? Help.
Message
De
21/02/2001 11:58:25
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Word 2000 OLE code only prints one .DOC no others? Help.
Divers
Thread ID:
00478033
Message ID:
00478033
Vues:
70
I am using the VFP/OLE code below to launch Word from VFP and print Word DOCs. It consistently prints one .DOC but no others.

Here is my environment:
Windows NT 4.00.1381
Word 2000 9.0.3821 SR-1
Visual FoxPro 6.0 SP4
HP LaserJet 5si

When it prints the one .DOC, Word is launched and I see what may be a printer status dialog, the printer icon shows up in the task bar, word closes and the document prints.

When I try to print the other documents, Word is launched, but I do not see what may be the printer status dialog, the printer icon shows up in the task bar, word closes, but the document doesn't print.

Would you know what is happening, and what to do to get every .DOC to print?

Please copy responses via email to beyner1@dmicorp.com. Thank you.

*--- ProbCode.PRG
* Problem Code.
*
* EXAMPLE: OpenAndPrintWordDoc("G:\Source Code\App\Reports\Report.DOC")

*----------------------------------------------
*
FUNCTION oLaunchWord()
RETURN CreateObject("Word.Application")
ENDFUNC

*-----------------------------------------------
*
FUNCTION oOpenWordDoc(toWord, tcFullPathAndWordDocNameWithExt)
LOCAL lnRetVal
lnRetVal = 0

IF TYPE("toWord") != 'O'
lnRetVal = lnRetVal + 2
ENDIF

IF NOT FILE(tcFullPathAndWordDocNameWithExt)
lnRetVal = lnRetVal + 1
ENDIF

RETURN IIF(lnRetVal = 0, ;
toWord.Documents.Open(tcFullPathAndWordDocNameWithExt), ;
lnRetVal)
ENDFUNC

*-----------------------------------------------
*
FUNCTION PrintWordDoc(toDocument)
LOCAL lnRetVal
lnRetVal = 0

#DEFINE wdPrintAllDocument 0
#DEFINE wdPrintSelection 1
#DEFINE wdPrintCurrentPage 2
#DEFINE wdPrintFromTo 3
#DEFINE wdPrintRangeOfPages 4

#DEFINE wdPrintDocumentContent 0

#DEFINE wdPrintAllPages 0

IF TYPE("toDocument") != 'O'
lnRetVal = lnRetVal + 2
ENDIF

IF lnRetVal = 0

* PrintOut([Background], [Append], ;
* [Range], [OutputFileName], [From], [To], [Item], ;
* [Copies], [Pages], [PageType], ;
* [PrintToFile], [Collate], [ActivePrinterMacGX], [ManualDuplexPrint], ;
* [PrintZoomColumn], [PrintZoomRow], [PrintZoomPaperWidth], [PrintZoomPaperHeight])

*!* toDocument.PrintOut(.T., , ;
*!* wdPrintAllDocument, "", "", "", wdPrintDocumentContent, ;
*!* "1", "", wdPrintAllPages, ;
*!* .F., .T., , , ;
*!* 0, 0, 0, 0)

toDocument.PrintOut(.T.)
ENDIF

RETURN lnRetVal
ENDFUNC
*
*-----------------------------------------------

*-----------------------------------------------
*
FUNCTION ExitWordWithoutSaving(toWord)
LOCAL lnRetVal
lnRetVal = 0

IF TYPE("toWord") != 'O'
lnRetVal = lnRetVal + 1
ENDIF

IF lnRetVal = 0
IF VarType(toWord) = 'O'
toWord.quit(0) && a parameter of 0 would close without saving.
* RELEASE oWord
toWord = .NULL.
ENDIF
ENDIF

RETURN lnRetVal
ENDFUNC

*-------------------------------------------------------
*
* EXAMPLE: OpenAndPrintWordDoc("G:\Source Code\SOW2\Reports\SowReport.DOC")
*
FUNCTION OpenAndPrintWordDoc(tcFullPathAndWordDocNameWithExt)
LOCAL lnRetVal
lnRetVal = 0

IF NOT FILE(tcFullPathAndWordDocNameWithExt)
lnRetVal = lnRetVal + 1
ENDIF

* Create an instance of Word.
LOCAL loWord
loWord = oLaunchWord()

* Make Word visible.
loWord.Visible = .t.

LOCAL loDocument
loDocument = oOpenWordDoc(loWord, tcFullPathAndWordDocNameWithExt)
IF TYPE("loDocument") != 'O'
WAIT WINDOW "ERROR: Can't open document!"
ENDIF

LOCAL lnPrintError
* lnPrintError = PrintWordDoc(loDocument)
lnPrintError = PrintWordDoc(loWord.ActiveDocument)
IF lnPrintError != 0
WAIT WINDOW "ERROR: Printing!"
ENDIF

ExitWordWithoutSaving(loWord)

RETURN
ENDFUNC
Répondre
Fil
Voir

Click here to load this message in the networking platform