VBA to print all files in a folder (1 Viewer)

papasmurfuo9

Registered User.
Local time
Today, 13:53
Joined
May 28, 2014
Messages
69
Hi, could anyone share code will print all files in a specific folder

the folder could contain, workbooks, PDFs and word documents - i need all printing to default printer


thank you!
 

papasmurfuo9

Registered User.
Local time
Today, 13:53
Joined
May 28, 2014
Messages
69
thanks - that seems specifically for PDFs? im after word/excel/pdf


i found this, but doesnt seem to work

Code:
Set shApp = CreateObject("shell.application")
Set shFolder = shApp.Namespace("Filepath")
Set shItems = shFolder.Items()
For Each shItem In shItems
  shItem.invokeverb "&Print"
Next
 

Orthodox Dave

Home Developer
Local time
Today, 21:53
Joined
Apr 13, 2017
Messages
218
There is an API function to print a file (any extension) here:
https://social.msdn.microsoft.com/F...print-copies-of-external-file?forum=accessdev

If you paste that function (including the top bit), then you can print a file using fPrintFile - for example fPrintFile("C:\Users\Dirk\Documents\SomePDF.pdf") but it doesn't have to be a pdf apparently.

To get the list of files from which you can call this function, here's some code:
Code:
Public Function PrintFiles(FolderName)
Dim NameOfFile, fsObj, FD, Fs, Fl 'Folder, Files collection, File
Dim DB As Database, FullPath As String

  Set fsObj = CreateObject("Scripting.FileSystemObject")
  Set FD = fsObj.GetFolder(FolderName)
  Set Fs = FD.Files
Set DB = CurrentDb()

For Each Fl In Fs
     NameOfFile = Fl.NAME

FullPath = FolderName & "\" & NameOfFile
fPrintFile(FullPath)
MsgBox("Has " & NameOfFile & " printed yet?")

Next

  Set fsObj = Nothing
  Set FD = Nothing
  Set Fs = Nothing
End Function
You may not need the message box in the above code. I added it to hold up the code because a long list of items to print might overflow the buffer.
 

Users who are viewing this thread

Top Bottom