Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing in word

Posted on 2000-04-26
17
Medium Priority
?
241 Views
Last Modified: 2010-05-02
Private Sub Main()
Set wrdApp = New Word.Application
    wrdApp.Documents.Open ("c:\Docs\Doc1.doc")
    wrdApp.ActiveDocument.PrintOut
   
    wrdApp.Documents.Close (wdDoNotSaveChanges)

    wrdApp.Quit
    Set wrdApp = Nothing
Exit Sub

The problem is that when I run this word will quit and ask me if I want to terminate the print job.  
How can I code it so that it waits until the print job has completed and then quits word?

Thanks in advance

Iain
0
Comment
Question by:iJolly4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +4
17 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2752042
try including a DoEvents statement before closing the app
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2752181
Try this line:
wrdApp.ActiveDocument.PrintOut Background:=False
0
 
LVL 7

Expert Comment

by:BarryTice
ID: 2752191
I've never tried it myself, iJolly4, but my understanding is you can do this with ShellExecute.

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub CmdHelp_Click()

Dim lngReturn As Long
Dim strPath As String
Dim strFile As String

strFile = "Doc1.doc"      'Name of your file
strPath = "C:\Docs\"       'Path to your file.

lngReturn = ShellExecute(Me.hwnd, "Print", strFile, "", strPath, 1)

End Sub

Hope this helps -- b.r.t.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:BarryTice
ID: 2752308
Erf -- Make that "Public Declare Function" a "Private Declare Function" or put the API definition in its own module.
0
 

Expert Comment

by:Jalen
ID: 2752409
Insert a DoEvents just before the
wrdApp.Documents.Close DoNotSaveChanges)
line
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2752439
Jalen,

Please, change your answer to a comment since AzraSound already suggested it.
0
 

Expert Comment

by:Jalen
ID: 2752517
My Apologies I did Not see Azrasounds Answer ...I didn't even look at the answers ..I just scrolled down and answered it ..again My apologies ...Well spotted ..Thanks ...
Jalen
Kerry(The Kingdom)
Ireland
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2752602
Jalen,

You have an option to transform your answer to a comment, please use it!
0
 

Expert Comment

by:Jalen
ID: 2752659
I already did change it!!!!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2752679
Sorry Jalen.

Where is iJolly4 now?
0
 

Expert Comment

by:Jalen
ID: 2752734
Emoreau...Now you've really lost me "Where is i jolly4 now".....I give up where are they ....*S*
Jalen
Kerry(The Kingdom)
Ireland
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2752808
No I simply hope that iJolly4 will surface saying if one of the comment is satisfying!
0
 

Accepted Solution

by:
olka earned 100 total points
ID: 2754338
i had the same problem. I solved it with using a timer, which calls a procedure to check the Printer status.
Put a timer with an interval e.g. of 60s in your MDI-form .
When the timer raises call a sub like this:
Sub checkWordPrintStatus(blnQuit As Boolean, tmrWordPrint As Timer)
  If WordApp.BackgroundPrintingStatus = 0 Or blnQuit = True Then
    ' if printerstatus = 0 (--> printing is finished) or MDI-Form is closed
    ' close MS-WORD without saving anything
   
    WordApp.Quit wdDoNotSaveChanges
   
    tmrWordPrint.Enabled = False                          'Timer zurücksetzen
  End If
End Sub


0
 

Author Comment

by:iJolly4
ID: 2755805
He has surfaced and the DoEvents statement was the first thing that I tried before mailing this.....................................................It didn't work.  I am just trying olka's solution.  BackgroundPrintingStatus was what I looked at but I foolishly continually checked its status that seemed to prevent word from printing - The timer may help.

I will let you all know.  Thanks for the help.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2756232
As I already posted, have you try this simple line? It works well for me:
wrdApp.ActiveDocument.PrintOut Background:=False
0
 

Expert Comment

by:polmorphism
ID: 7409379
   msWord.Application.Options.PrintBackground = False
    msWord.ActiveDocument.PrintOut , , wdPrintAllDocument, , , , , , , , False
    msWord.ActiveDocument.Close wdDoNotSaveChanges
    msWord.Quit
    Set msWord = Nothing
0
 

Author Comment

by:iJolly4
ID: 7433124
Thanks for that polymorphism.

Looks a much simpler way of doing things.  Unfortunately I awarded the points over 2 years ago...You would have got them though had you been a little bit quicker with your reply.  Thanks for the help though - If I get the time I may change my code.

Cheers
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question