Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Print PDF from VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Tangard - 10 Mar 2007 07:05 GMT
A long shot, maybe:  Is there way, maybe using Shell, to print a PDF file from
VBA code?

Goal: To print all PDFs in a folder *in order* (alpha by filename), in a way
that doesn't require opening each one or combining them into a large file(s).

Selecting multiple PDF files from an Explorer window and clicking File-> Print
does in fact send them to printer, but the print in some bizarre order I can't
discover!

Can I use VBA's FileSearch property to collect the filenames & then call another
macro within that loop that sends each file to the printer, with a DoEvents line
(or some equivalent to Background:=False) after each one, so they'll print one
at a time?

Is this clear?  Is there an easier way somewhere?

Word 2003, WinXP, Acrobat 6.0 standard.

Thanks in advance
Mark Tangard
Mark Tangard - 10 Mar 2007 14:03 GMT
In case anyone's interested, I found a nice one already:
PDF Toolkit.  http://www.accesspdf.com/index.php?topic=pdftk

It's a DOS program, but not much work to build a VBA macro that runs it.

And it's free!

MT

> A long shot, maybe:  Is there way, maybe using Shell, to print a PDF
> file from VBA code?
[quoted text clipped - 18 lines]
> Thanks in advance
> Mark Tangard
jim - 12 Mar 2007 13:41 GMT
Mark -

Do a search on adobe.com for "Programming Acrobat JavaScript Using
Visual Basic".  It is Tech Note #5417 published in August 2002.  I
have used it to program some simple stuff with VB6 to save PDFs to
various directories based on content, something JavaScript is weak on
but that VB6 can do easily.  The nice thing about it is that it is all
VB based and you don't need to go to DOS.

I am sure that will meet your needs.

jim

>In case anyone's interested, I found a nice one already:
>PDF Toolkit.  http://www.accesspdf.com/index.php?topic=pdftk
[quoted text clipped - 27 lines]
>> Thanks in advance
>> Mark Tangard
Karl E. Peterson - 12 Mar 2007 22:39 GMT
> A long shot, maybe:  Is there way, maybe using Shell, to print a PDF file from
> VBA code?
>
> Goal: To print all PDFs in a folder *in order* (alpha by filename), in a way
> that doesn't require opening each one or combining them into a large file(s).

I'd think you could do that with a series of ShellExecute calls using the "print"
verb.  Try this:

  Private 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

  Public Function PrintDoc(ByVal DocFile As String) As Long
     ' Uses the "print" verb as defined in the registry
     PrintDoc = ShellExecute(0&, "print", DocFile, vbNullString, vbNullString,
vbNormalFocus)
  End Function

Signature

.NET: It's About Trust!
http://vfred.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.