• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Printing pdf-files

EddyVW

New Member
Hi,
I created following macro to move 3 files from one folder to another
Code:
Sub InpDat()
  Set fso = CreateObject("scripting.filesystemobject")
  fso.MoveFile Source:="C:\FinSend\*.pdf", Destination:="D:\PdfF" ' Move pdf's
End Sub
New I would like to make a printout of those 3 pdf-files
Thanks
 
Welcome to the forum!

If you mean print a paper copy, that depends on your pdf application. You need to know what command line parameters it accepts.

To manually test the proper shell command line string: press WIN+R and manually type the pdf application's EXE full path, pdf filename, and command line switches. Be sure to encapsulate strings for the application's EXE path and the pdf filename path with quote characters if it contains a space character.

The code is for the old acrobat reader application. Obviously, you need to iterate all the pdf files. I don't think the pdf applications have a batch print option you can test to see. We can add that later if "your modified" test sub works for you.

Put all this in a Module and modify the sub Test_Printpdf's fn value.
Code:
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
  (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long

Sub Test_Printpdf()
  Dim fn$
  fn = "C:\Users\ken\Dropbox\Excel\pdf\p1.pdf"
  PrintPDf fn
End Sub

Sub PrintPDf(fn$)
  Dim pdfEXE$, q$

  pdfEXE = ExePath(fn)
  If pdfEXE = "" Then
    MsgBox "No path found to pdf's associated EXE.", vbCritical, "Macro Ending"
    Exit Sub
  End If

  q = """"
  'http://help.adobe.com/livedocs/acrobat_sdk/10/Acrobat10_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat10_SDK_HTMLHelp&file=DevFAQ_UnderstandingSDK.22.31.html
  '/s/o/h/p/t
  Shell q & pdfEXE & q & " /s /o /h /t " & q & fn & q, vbHide
End Sub

Function ExePath(lpFile As String) As String
  Dim lpDirectory As String, sExePath As String, rc As Long
  lpDirectory = "\"
  sExePath = Space(255)
  rc = FindExecutable(lpFile, lpDirectory, sExePath)
  sExePath = Left$(sExePath, InStr(sExePath, Chr$(0)) - 1)
  ExePath = sExePath
End Function

Sub Test_ExePath()
  MsgBox ExePath(ThisWorkbook.FullName)
  MsgBox ExePath("C:\Users\ken\Dropbox\Excel\pdf\ken.pdf")
End Sub
 
Back
Top