iJolly4
asked on
Printing in word
Private Sub Main()
Set wrdApp = New Word.Application
wrdApp.Documents.Open ("c:\Docs\Doc1.doc")
wrdApp.ActiveDocument.Prin tOut
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
Set wrdApp = New Word.Application
wrdApp.Documents.Open ("c:\Docs\Doc1.doc")
wrdApp.ActiveDocument.Prin
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
try including a DoEvents statement before closing the app
Try this line:
wrdApp.ActiveDocument.Prin tOut Background:=False
wrdApp.ActiveDocument.Prin
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.
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.
Erf -- Make that "Public Declare Function" a "Private Declare Function" or put the API definition in its own module.
Insert a DoEvents just before the
wrdApp.Documents.Close DoNotSaveChanges)
line
wrdApp.Documents.Close DoNotSaveChanges)
line
Jalen,
Please, change your answer to a comment since AzraSound already suggested it.
Please, change your answer to a comment since AzraSound already suggested it.
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
Jalen
Kerry(The Kingdom)
Ireland
Jalen,
You have an option to transform your answer to a comment, please use it!
You have an option to transform your answer to a comment, please use it!
I already did change it!!!!
Sorry Jalen.
Where is iJolly4 now?
Where is iJolly4 now?
Emoreau...Now you've really lost me "Where is i jolly4 now".....I give up where are they ....*S*
Jalen
Kerry(The Kingdom)
Ireland
Jalen
Kerry(The Kingdom)
Ireland
No I simply hope that iJolly4 will surface saying if one of the comment is satisfying!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
I will let you all know. Thanks for the help.
As I already posted, have you try this simple line? It works well for me:
wrdApp.ActiveDocument.Prin tOut Background:=False
wrdApp.ActiveDocument.Prin
msWord.Application.Options .PrintBack ground = False
msWord.ActiveDocument.Prin tOut , , wdPrintAllDocument, , , , , , , , False
msWord.ActiveDocument.Clos e wdDoNotSaveChanges
msWord.Quit
Set msWord = Nothing
msWord.ActiveDocument.Prin
msWord.ActiveDocument.Clos
msWord.Quit
Set msWord = Nothing
ASKER
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
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