Option Compare Database
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 PrintPDF(FullPath As String)
Dim printThis
printThis = PrintThisDoc(FullPath)
End Sub
Option Compare Database
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 PrintPDF(FullPath As String)
Dim printThis
printThis = PrintThisDoc(0, FullPath)
End Sub
Option Compare Database
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 PrintPDF(FullPath As String)
Dim printThis
printThis = PrintThisDoc(0, FullPath)
End Sub
Private Sub cmdPrintThem_Click()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Dim vrtSelectedItem As Variant
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim myfolder As folder
Dim myfile As file
TryAgain:
With fd
.InitialView = msoFileDialogViewDetails ' msoFileDialogViewThumbnail
.Title = "Folder Selector"
'.InitialFileName = theFile
.ButtonName = "Use this folder"
.AllowMultiSelect = False
'The user pressed the action button.
If .Show = True Then
If .SelectedItems.Count = 0 Then
MsgBox "You didn't make a valid selection. Try again!"
GoTo TryAgain
End If
MsgBox .SelectedItems(1)
'...more code to actually do stuff with the files and subfolder(s) found here
Set myfolder = fs.GetFolder(.SelectedItems(1))
For Each myfile In myfolder.Files
If fs.getextensionname(myfile.Name) = "pdf" Then
MsgBox myfile.Name
PrintPDF (myfile.Name)
End If
Next myfile
Else
'bailed
End If
End With
End Sub
You need a Reference to the MS Office xx.0 Object library
That'll get you the FileDialog box
So this is the start, code to select a folder
Open in new window
Now to flesh out this
'...more code to actually do stuff with the files and subfolder(s) found here
What will be used to handle your PDFs?
Acrobat?
Acrobat Reader?
what version(s)
Something else?
A lot depends on the answer.
VBA can't deal with PDFs straight-up.
Something external has to be invoked/shelled and so paths to the executable can become important