excel 按顺序将Pdf文件发送到打印机

kqhtkvqz  于 2023-03-13  发布在  其他
关注(0)|答案(1)|浏览(164)

我在excelvba相当新。我试图生成一个代码,允许发送pdf到打印机在一个序列。我开发了一个代码,但代码不理解序列(按名称排序)。我该如何纠正我的代码?
代码在这里

Sub Send_to_Printer_by_in_a_sequence()
    Dim way As String, Pdfs As String
    
    Application.ScreenUpdating = False
    
    way = ThisWorkbook.Path & Application.PathSeparator
    
    Pdfs = Dir(way & "*.pdf")
    
    While Pdfs <> ""
        CreateObject("Shell.Application").Namespace(0).ParseName(way & Pdfs).InvokeVerb ("Print")
        Application.Wait Now + TimeSerial(0, 0, 4)
        Pdfs = Dir
    Wend
    
    On Error GoTo 10
    AppActivate "Acrobat Reader", True
    SendKeys "%{F4}", True
    Application.Wait Now + TimeSerial(0, 0, 3)
    
10  Application.ScreenUpdating = True
    
    MsgBox "All pdfs has been sent to printer."
End Sub
4nkexdtk

4nkexdtk1#

您可以收集您的pdf文件的名称,排序阵列,因为你喜欢和发送到打印机在任何序列挑选名称从阵列

Sub collectnames()
Dim way As Object, wFolder as object, Pdfs() As String
count = 0
Set way = CreateObject("Scripting.FileSystemObject")
Set wFolder = way.GetFolder(Path)
For Each x In wFolder.Files
If InStr(1, x.Name, ".pdf") > 0 Then
count = count + 1
Pdfs(count) = x.Name
End If
 Next x
 End sub

相关问题