Member_2_1348041
asked on
Printing to Microsoft Office Document Image Writer launches the viewer
I want to create an MDI file by printing to Microsoft Office Document Image Writer. That part is easy; the VB6 code below does it quite nicely.
But there is one problem with it. The moment it creates the file ... it launches the MDI viewer. I don't want it to launch the viewer. I will be processing the file myself, through code.
How do I stop it from launching the viewer!?
But there is one problem with it. The moment it creates the file ... it launches the MDI viewer. I don't want it to launch the viewer. I will be processing the file myself, through code.
How do I stop it from launching the viewer!?
For Each oPrinter In Printers
MsgBox oPrinter.DeviceName
If InStr(1, oPrinter.DeviceName, "Microsoft Office Document Image Writer", vbTextCompare) > 0 Then
Exit For
End If
Next
If Not oPrinter Is Nothing Then
Set oWord = New Word.Application
oWord.ActivePrinter = oPrinter.DeviceName
Set oWordDoc = oWord.Documents.Open(strNew)
oWordDoc.SaveAs Environ("TEMP") & "\eek.mdi"
oWordDoc.PrintOut Range:=wdPrintAllPages, Collate:=True, PrintToFile:=True, OutputFileName:=Environ("TEMP") & "\eek.mdi"
oWordDoc.Close False
Set oWordDoc = Nothing
oWord.Quit False
Set oWord = Nothing
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yeah, the basic shell command is useless for passing parameters. I use the ShellExecute API. See the vbAccelerator page below for details on using that. It shows how to print a document.
http://www.vbaccelerator.com/codelib/shell/shellex.htm
http://www.vbaccelerator.com/codelib/shell/shellex.htm
ASKER
<shudder>
Dude, this is nuts. I made a small change and guess what, now it works! Check it out. So thankfully I don't need to try and run it as a command line argument.
Now then, all I need next is to convert a PDF to images, and then I'm laughing all the way to the bank.
P
See code:
Dude, this is nuts. I made a small change and guess what, now it works! Check it out. So thankfully I don't need to try and run it as a command line argument.
Now then, all I need next is to convert a PDF to images, and then I'm laughing all the way to the bank.
P
See code:
For Each oPrinter In Printers
If InStr(1, oPrinter.DeviceName, "Microsoft Office Document Image Writer", vbTextCompare) > 0 Then
Exit For
End If
Next
If Not oPrinter Is Nothing Then
sDriver = oPrinter.DeviceName
End If
Set oPrinter = Nothing
Set oWord = New Word.Application
Set oWordDoc = oWord.Documents.Open(strNew)
oWord.PrintOut False, , , Environ("TEMP") & "\eek.mdi"
oWordDoc.Close
Set oWordDoc = Nothing
oWord.Quit
Set oWord = Nothing
strNew = Environ("TEMP") & "\eek.mdi"
ASKER
pardon.
again:
again:
For Each oPrinter In Printers
If InStr(1, oPrinter.DeviceName, "Microsoft Office Document Image Writer", vbTextCompare) > 0 Then
Exit For
End If
Next
If Not oPrinter Is Nothing Then
sDriver = oPrinter.DeviceName
End If
Set oPrinter = Nothing
Set oWord = New Word.Application
oWord.ActivePrinter = sDriver
Set oWordDoc = oWord.Documents.Open(strNew)
oWord.PrintOut False, , , Environ("TEMP") & "\eek.mdi"
oWordDoc.Close
Set oWordDoc = Nothing
oWord.Quit
Set oWord = Nothing
ASKER
I think the main difference is that the printout is not background, forcing it to show a little dialog saying printing page 1 of ... going through the pages 1, 2, 3, 4. And so it always includes all the pages. Problem solved.
this was bizarre. A whole morning of my life that I'll never get back.
this was bizarre. A whole morning of my life that I'll never get back.
No but you've added to the wealth of your experience. ;)
ASKER
Hell yeah. The School of Hard Knocks. LOL
ASKER
HOWEVER, I've since come up against an even worse problem. The output from the .Printout call is inconsistent. I tried this with a four-page document. And the mdi file contains ... well. Sometimes one page. Sometimes two. Sometimes all four.
Oh the joy.
I suppose you don't know how to send a word document to a specified printer through a shell (command line) commannd, do you? I'm now thinking I'll just invoke it through a synchronous shell; that is, IF I can work out how to do it.