PDA

Click to See Complete Forum and Search --> : Printing from Word problem


DonH
Aug 10th, 2004, 03:23 PM
I have a VBA script to open a word document, put stuff in it, then print it and close the whole application.

It works great when running on Win2k with Office 2k. Then I run it on XP with Office XP and it won't print unless I take out the quit command. Of course that leaves Word open, which is not what I want.

Also, if someone could tell me how to script having some text on the left and some text on the right in the header (in the below case it is MEDICAL RECORD left justified and PROGRESS NOTES right justified) I'd appreciate it.

Here is the script:

Const wdSeekCurrentPageHeader = 9, wdPrintView = 3
set oWord = CreateObject("Word.Application")
with oWord
.Documents.Open("c:\obchart3\progressnotetemplate1.doc")
.Documents.Open("c:\obchart3\patient.tab")
.Selection.WholeStory
.Selection.Copy
.ActiveDocument.Close
If .ActiveWindow.View.SplitSpecial <> wdPaneNone Then
.ActiveWindow.Panes(2).Close
End If
With .ActiveWindow.ActivePane.View
.Type = wdPrintView
.SeekView = wdSeekCurrentPageHeader
End With

with .Selection
.Font.Bold = wdToggle
.TypeText("MEDICAL RECORD PROGRESS NOTES")
.TypeParagraph
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.TypeText("PATIENT'S DATA (FMPSSN, NAME, DOB, UNIT, GRADE, BRANCH)")
.TypeParagraph
.Paste
.Font.Bold = wdToggle
.TypeParagraph
.TypeParagraph
end With
.Documents.Open("c:\obchart3\progressnote.tab")
.Selection.WholeStory
.Selection.Copy
.ActiveDocument.Close
.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
with .Selection
.Paste
.WholeStory
.Font.Size = 8
end with
.printout()
.quit(0)

end with


UPDATE : Why do I always have the problems nobody can solve? sigh

Here is what I tried to do to fix this. I made a MACRO that does the same thing. It worked fine on the 2k and XP machines I tested it on. Then I went to another clinic and tried it on their XP machines. All exactly the same as the one I tested on. Won't work. It keeps coming up saying WAITING FOR PRINT JOB TO FINISH I check the queue and there is the job. But it won't ever print.

IF I manually do each step in the macro it works just fine on these machines. I recorded the macro on one of them. Tried running it. No go.

:afrog:

What is the difference between doing it step by step and running the macro?

DonH
Aug 11th, 2004, 06:09 PM
How do I close Word from DOS like in a batch file?

Ecniv
Aug 12th, 2004, 05:28 AM
Ok, so try not quitting the word app and see if it works. If it does, then all that is happening is that there isn't enough time between printing the doc and closing the app.

Use Doevents a couple of times or a delay loop before quitting. If possible (and I haven't looked into Word too much) see if there is a print status, if so loop until that changes and use doevents to pass back to windoze to allow screen updating.


Vince