Results 1 to 2 of 2
  1. #1
    Khatuaaccess is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jul 2016
    Posts
    13

    vba to print all pdfs from a folder

    Hi,

    I have the below code which pick 1 pdf from a folder to print.

    Now i want to pick all pdfs from that location and send it to print. also want to close the acrobat adobe reader closed.


    Option Explicit
    Public 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 PrintThisDoc(formname As Long, FileName As String)
    On Error Resume Next
    Dim X As Long
    X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
    End Function

    Sub testPrint()
    Dim printThis
    Dim strDir As String
    Dim strFile As String





    strDir = "C:\DailyData\Prasanta Data\Access\Deployment\Letters"
    strFile = "GHI.pdf"





    printThis = PrintThisDoc(0, strDir & strFile)

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    ''usage on button click:
    sub button_click()
    PrintAllFilesInDir "c:\folder"
    end sub


    Code:
      ' put this at the top of the module
    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 Sub PrintAllFilesInDir(ByVal pvDir)
    Dim vFil, vTargT
    Dim i As Integer
    Dim fso
    Dim oFolder, oFile
    Dim vOutFile
    
    On Error GoTo errImp
    If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(pvDir)
    
    For Each oFile In oFolder.Files
        vFil = pvDir & oFile.Name
        If InStr(vFil, ".pdf") > 0 Then      'ONLY DO PDF FILES
                Call ShellExecute(0, "print", vFil, "", "", 1)
        End If
    Next
    
    Set fso = Nothing
    Set oFile = Nothing
    Set oFolder = Nothing
    MsgBox "Done"
    Exit Sub
    
    errImp:
    MsgBox Err.Description, vbCritical, "clsImport:ImportData()" & Err
    Exit Sub
    Resume
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need access vba to Print all pdf from a fix folder
    By Khatuaaccess in forum Access
    Replies: 9
    Last Post: 08-07-2016, 08:35 AM
  2. Print PDFs from Sharepoint
    By mrmims in forum Programming
    Replies: 2
    Last Post: 12-19-2015, 08:49 PM
  3. Print linked pdfs with their associated reports
    By HoopaWildlife in forum Access
    Replies: 1
    Last Post: 09-08-2011, 06:40 PM
  4. Print linked pdfs within an Access Report II
    By cjwagner in forum Reports
    Replies: 3
    Last Post: 05-30-2011, 04:25 PM
  5. Print linked pdfs within an Access Report
    By alpruett in forum Reports
    Replies: 6
    Last Post: 05-20-2011, 05:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums