Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Word after Print from Extra

Status
Not open for further replies.

JeaShe

Programmer
Mar 9, 2004
89
US
In my code I send a Word doc to the printer. Then I close the doc and the Word app. Problem is I can't control how long to wait between sending the doc to the printer and closing the Word doc and then app.

I've tried several variations, but here is one I'm working with now:

Set objRange = objDoc.Content 'CREATE THE RANGE OBJECT
objDoc.PrintOut, 1
objDoc.Close (wdDoNotSaveChanges)
objApp.Quit
Set objApp = nothing

I usually get the message asking if I want to close the doc it will stop printing. Or, it will change the Normal template ( I believe that is at the objApp.Quit part)

Anyhow, I would like to know some command to make the Extra wait until the printing is done then close the doc (without saving it) and eventually Word too.

Is there another way to print a doc with info the macro collect aside from opening a word processing program that might help me avoid this problem altogether?

Thanks!
 
This is vbscript that'll return the print jobs. The biggest problem you're going to have with EB is that you can't do a For Each loop. If you look into the WMIService, you might be able to get it down to a single item rather than a collection.
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_PrintJob")'
Wscript.Echo "Total print jobs in queue: " & colPrintJobs.Count
For Each objPrintJob in colPrintJobs
 intTotalPages = intTotalPages + objPrintJob.TotalPages
 If objPrintJob.TotalPages > intMaxPrintJob Then
  intMaxPrintJob = objPrintJob.TotalPages
 End If
 Wscript.Echo "Owner: " & objPrintJob.Owner
 Wscript.Echo "Document: " & objPrintJob.Document
Next
Wscript.Echo "Total pages in queue: " & intTotalPages
Wscript.Echo "Largest print job in queue: " & intMaxPrintJob

As far as the messages.
objApp.displayAlerts = False
 
How much scraped info are you wanting to send to the printer JeaShe?

<off topic>
As far as collections in EB goes, the followings not nearly as convienent as the for each object VBA uses but an exceptable work around if your intent on using EB.

VBA
For Each w In Workbooks
If w.Name <> "Name I'm Looking For" Then
w.Close savechanges:=True
End If
Next w

EB
For x = 1 to Workbooks.count
Set CurrentBook = Workbooks.Item(1)
If CurrentBook.Name <> "Name I'm Looking For" Then
CurrentBook.Close savechanges:=True
End If
Next x


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
You can do a
For i = 0 To colPrintJobs.Count - 1

The problem is you can't do a simple
Set objPrintJob = colPrintJobs.Item(i)

The Item property needs a string and I couldn't figure out what values would pull the appropriate print job.
 
This sounds like something I can work with. I'll let you all know how it works for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top