I’m trying to print all files inside a folder with this code but something is not working correctly…
Sub Bulk_Print_From_Folder() Dim k As Variant Dim n As Variant Dim oFile As Object Dim oFiles As Object Dim oFolder As Object Dim Path As Variant Dim vItem As Object Path = "C:\Testing Folder" With CreateObject("Shell.Application") Set oFolder = .Namespace(Path) If oFolder Is Nothing Then MsgBox "The Folder :" & vbLf & """" & Path & """ was Not Found.", vbCritical Exit Sub End If End With Set oFiles = oFolder.Items oFiles.Filter 64, "*.pdf;*.jpg;*.png;*.txt" For n = 0 To oFiles.Count - 1 Set oFile = oFiles.Item(n) For k = 0 To oFile.Verbs.Count - 1 Set vItem = oFile.Verbs.Item(k) If Not vItem Is Nothing Then If Replace(vItem, "&", "") = "Print" Then vItem.DoIt End If Next k Next n End Sub
»» I have macros enabled and default printer defined… The printer is working correctly.
»» I noticed that I don’t see the printer icon in Taskbar after hit the button to execute this code. And if it maters, I’m using Office 2007 Ultimate.
»» I know that it finds the folder. I tested by altering the folder name on the code and I got the message
MsgBox "The Folder :" & vbLf & """" & Path & """ was Not Found.", vbCritical
This are my project references:
A’m I missing something?
There is nothing wrong with the code.
The problem is with the default program set for opening the image file. If you right click on the image file, you will not see the
Control panel and go to
Default Apps. Change the default app of
Photo Viewer to say
Now right click on the image file and you will see the
vItem will have
If you have a mix of files in that folder and you do not see a
Depending on OS, you may see
&Print out or something in a regional language. You can test that by using this code
For n = 0 To oFiles.Count - 1 Set oFile = oFiles.Item(n) For k = 0 To oFile.Verbs.Count - 1 Set vItem = oFile.Verbs.Item(k) If Not vItem Is Nothing Then Debug.Print vItem End If Next k Next n
So you may want to change the code
If Replace(vItem, "&", "") = "Print" Then
If InStr(1, vItem, "&Print") Then
InStr(1, vItem, "imprimir", vbTextCompare) '<~~ See Chat below quesiton