|
-
Jul 19th, 2004, 11:16 AM
#1
Thread Starter
Frenzied Member
printing a word document
Add a reference to 'Microsoft Word 9.0 Object Library'
I'm trying to print a document with this code:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim wrdApp As New Word.Application
wrdApp.Documents.Open("C:\temp\temp.doc")
wrdApp.Dialogs.Item(Word.WdWordDialog.wdDialogFilePrint).Show()
wrdApp.Visible = False
wrdApp.ActiveDocument.Close()
wrdApp.Quit()
End Sub
The problem is, when the print dialog shows up and I click OK to print, I get the Message 'Word is currently printing. Quitting Word will cancel all pending print jobs. Do you want to quit Word?'
If I click Yes the document is not printed but Word disappears. Clicking No, the document prints but the Word application is still open and has to be closed manually.
Is there a way to tell when the Word app is fininished sending the document to the printer so I can call wrdApp.Quit()?
-
Jul 19th, 2004, 09:11 PM
#2
Frenzied Member
Not sure if this will help you or not. I have not printed a Word doc from .NET. But, in a Word macro, I've had to use
Code:
ActiveDocument.PrintOut (False)
which suspends the macro until the print job is done, avoiding a similar dialog box.
FWIW, I tried your code verbatim, printed to Adobe PDF, and did not have any problems.
Best of luck,
Mike
-
Aug 18th, 2004, 11:19 AM
#3
Frenzied Member
wey97:
Looking at the Word VB Help Heap, in PrintOut:
wrdApp.ActiveDocument.PrintOut(Background:=False)
Means that Printing is in the foreground, and the macro shouldn't continue util the print job is done. ???
I've started a thread about how to pass a print file name to Adobe PDF writer as the default Word Printer. Any ideas?
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 18th, 2004, 11:26 AM
#4
Thread Starter
Frenzied Member
I was using the .PrintOut method but I had to make a custom dialog to get the page range. It was screwing up the page range so I went to the System Print Dialog. Plus you get all the other printing options with the system dialog.
The only way around it was to wait a certain amount of time (like 10 seconds) to make sure the document finished printing and kill the Word process. The problem with that is if you click Print and immediately exit the app you have an extra Word process running in the background.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|