VBA代码用于在文件夹内打印文件

时间:2019-06-03 08:59:15

标签: excel vba

我需要一个VBA代码来打印文件夹中的所有pdf文件,我的代码没有显示任何错误,但是没有打印。

我正在使用Windows 10

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"

    For n = 0 To oFiles.Count - 
        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

0 个答案:

没有答案