ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Printing Word Document using Excel Programming hangs Word (https://www.excelbanter.com/excel-programming/312077-printing-word-document-using-excel-programming-hangs-word.html)

alan

Printing Word Document using Excel Programming hangs Word
 
I have an Excel spreadsheet that prints an MS Word
document with field code links back to values in the
Excel Spreadsheet.

Basically I cycle through all the rows in the Excel
spreadsheet and print the Word Document for each line in
the Excel file.

I built the application using Windows XP, and Office XP
2002--works fine. I have tried running it on a PC
running Windows XP, and Office 2000. The Word document
printing hangs without a 3-second wait. At the end it
will not end properly, and prompts the user that "Ending
Word will stop the print jobs (2 print jobs left are
left)".

Any idea how to overcome this? Below is the basic code I
am using:

Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.documents.Open
("C:\fldr\Templates\FormR1.dot")

Do until eof
wdApp.activedocument.PrintOut Background:=True,
Copies:=1, Collate:=True

*** This section of code will not work in Word 2000 ***
' lngstatus = 1 'wdApp.BackgroundPrintingStatus
' Do Until lngstatus = 0
' lngstatus = wdApp.BackgroundPrintingStatus
' Loop
*** This is the workaround with a wait included ***
newhour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now())
waitTime = TimeSerial(newhour,newMinute,newSecond)
Application.Wait waitTime
Loop
*** Hangs on the following line, even with a wait added
***
wdApp.activedocument.Close
wordfile = wdApp.Quit


Thanks for your help!!



All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com