Print file with FSO?

E

Ed from AZ

I'm trying to write a macro that will let me find a folder and simply
print each file in that folder to the default printer. The files are
PDFs. Using the FileSystemObject, I can get the Folder and File
objects. But I can't seem to find a "Print" method in there
anywhere?? WHat do I use?

Ed
 
S

Steve Yandl

Ed,

I've done this from a vbs file before and my approach was to use
acrord32.exe ("acrobat reader") which is typically located at "C:\Program
Files\Adobe\Acrobat 7.0\Reader\acrord32.exe" If you're doing this from VBA,
you would probably use the Shell function to launch the executable. To
print, you send it /t as an argument followed by the file name of the pdf
including path (which you will have from FSO). You can also send arguments
for printer name and printer driver.

The hassle with using acrord32.exe is that it doesn't close as expected when
the print job finishes. In my script, I used WMI to kill the process after
pausing long enough for print jobs to be spooled.

Steve Yandl
 
D

Doug Robbins - Word MVP

See the article "Print all documents in a given folder to a single print
file" at:

http://www.word.mvps.org/FAQs/MacrosVBA/PrintAllDocsInFldr.htm

Replace

Application.PrintOut _
Background:=False, _
Append:=True, _
OutputFileName:="c:\myfile.prn", _
PrintToFile:=True, _
FileName:=MyPath & MyName

with

Application.PrintOut Background:=False

to print to the default printer

Also see the article "How to allow the user to browse to and select a
folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/BrowsDialog.htm




--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

Ed from AZ

Hi, Steve. As I was researching this, i found references to using
Shell with

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strF)
Set objFolderItem = objFolder.ParseName(strI)
objFolderItem.InvokeVerbEx ("Print")

but it didn't seem to work. I keep erroring on
Set objFolderItem = objFolder.ParseName(strI)
The code finds the item and strI is correct, but objFolderItem is
always Nothing. My error is:
Error Number: 13
Error Is: Type mismatch

I'm not familiar with Shell, so I'm not sure how to invoke the
application and then quit it.

Ed
 
S

Steve Yandl

Ed,

Open VBE, call 'Help' and enter the terms shell and function to get the full
syntax.

Here is a small example that prints C:\Test\Map.pdf on the default printer.
However, despite using Shell to insist that Acrobat reader be minimized with
focus, it only starts that way and then shows in a normal window while the
pdf prints. Not ideal but it can be made to do close to what you want.

____________________________

Sub PrintPDF()
Dim strPDF As String
Dim strReader As String
Dim RetVal

strPDF = "C:\Test\Map.pdf"
strReader = "C:\Program Files\Adobe\Acrobat 7.0\Reader\acrord32.exe"

RetVal = Shell(strReader _
& " /t " & strPDF, vbMinimizedFocus)

End Sub

__________________________________

Steve Yandl



Hi, Steve. As I was researching this, i found references to using
Shell with

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strF)
Set objFolderItem = objFolder.ParseName(strI)
objFolderItem.InvokeVerbEx ("Print")

but it didn't seem to work. I keep erroring on
Set objFolderItem = objFolder.ParseName(strI)
The code finds the item and strI is correct, but objFolderItem is
always Nothing. My error is:
Error Number: 13
Error Is: Type mismatch

I'm not familiar with Shell, so I'm not sure how to invoke the
application and then quit it.

Ed
 
E

Ed from AZ

Thanks, Steve. I'll keep working on it.

Ed


Ed,

Open VBE, call 'Help' and enter the terms shell and function to get the full
syntax.

Here is a small example that prints C:\Test\Map.pdf on the default printer..
However, despite using Shell to insist that Acrobat reader be minimized with
focus, it only starts that way and then shows in a normal window while the
pdf prints.  Not ideal but it can be made to do close to what you want.

____________________________

Sub PrintPDF()
Dim strPDF As String
Dim strReader As String
Dim RetVal

strPDF = "C:\Test\Map.pdf"
strReader = "C:\Program Files\Adobe\Acrobat 7.0\Reader\acrord32.exe"

RetVal = Shell(strReader _
  & " /t " & strPDF, vbMinimizedFocus)

End Sub

__________________________________

Steve Yandl

Hi, Steve.  As I was researching this, i found references to using
Shell with

  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.Namespace(strF)
  Set objFolderItem = objFolder.ParseName(strI)
  objFolderItem.InvokeVerbEx ("Print")

but it didn't seem to work.  I keep erroring on
  Set objFolderItem = objFolder.ParseName(strI)
The code finds the item and strI is correct, but objFolderItem is
always Nothing.  My error is:
  Error Number: 13
  Error Is: Type mismatch

I'm not familiar with Shell, so I'm not sure how to invoke the
application and then quit it.

Ed








- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top