I'm just trying to batch print a large amount of files from a folder. The folder contains multiple file types, and I just want to invoke the print method equivalent to Right-Click > Print
.
It seems like I should be able to do this using the InvokeVerb
method of Shell32.FolderItem
object.
So, I can't figure out why, when I run the code below, nothing prints.
Any ideas?
( GetFolder
is just a wrapper for the Shell32.BrowseForFolder
function which returns the path to the folder selected. That function works without issue. For testing you can just replace with a path to a folder.)
Sub printFOO()
Dim shApp As Shell32.Shell
Dim srFSO As Scripting.FileSystemObject
Dim strPath As String
Dim shFIcol As Shell32.FolderItems
Dim shFIx As Shell32.FolderItem
Dim shFLDx As Shell32.Folder
Dim lngX As Long
Set shApp = New Shell32.Shell
Set srFSO = New Scripting.FileSystemObject
strPath = GetFolder("Choose a folder...")
Set shFLDx = shApp.NameSpace(strPath)
Set shFIcol = shFLDx.Items()
For Each shFIx In shFIcol
'For lngX = 0 To shFIx.Verbs.Count
'Debug.Print shFIx.Verbs.ITEM(lngX).Name
'Next
'msgbox("printing "&shFIx.name)
shFIx.InvokeVerb ("&Print")
DoEvents
Next
End Sub
Okay, so I still don't have an answer as to WHY the
InvokeVerb
method was not working to print, but I do have a way to print files now using theShellExecute
function suggested by @Radek.Figured I would share my working code here. Feel free to suggest improvements ;)