首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Print_All_PDF_Files_in_Folder()

Print_All_PDF_Files_in_Folder()
EN

Stack Overflow用户
提问于 2022-08-11 05:27:24
回答 1查看 41关注 0票数 -1

我一直在使用这段代码从工作中的文件夹中打印PDF,但是代码不再起作用了。我在家里远程工作,我已经更新了文件路径,我仍然收到一个运行时53错误代码。有人能帮忙吗?

代码语言:javascript
复制
Public Sub Print_All_PDF_Files_in_Folder()
    Dim folder As String
    Dim PDFfilename As String
    
    folder = "C:\Users\16468\Desktop\CONF\TAXES"    'CHANGE AS REQUIRED
    If Right(folder, 1) <> "\" Then folder = folder & "\"
       
    PDFfilename = Dir(folder & "*.pdf", vbNormal)
    While Len(PDFfilename) <> 0
        Print_PDF folder & PDFfilename
        PDFfilename = Dir()  ' Get next matching file
    Wend
End Sub

Private Sub Print_PDF(sPDFfile As String)
    Shell "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe /p /h " & Chr(34) & sPDFfile & Chr(34), vbNormalFocus
End Sub
EN

回答 1

Stack Overflow用户

发布于 2022-08-12 00:45:57

它应该印在任何东西上:

代码语言:javascript
复制
Option Explicit
#If VBA7 Then
    Private Declare PtrSafe Function ShellExecute _
        Lib "shell32.dll" Alias "ShellExecuteA" _
            (ByVal hwnd As LongPtr, _
             ByVal lpOperation As String, _
             ByVal lpFile As String, _
             ByVal lpParameters As String, _
             ByVal lpDirectory As String, _
             ByVal nShowCmd As Long) _
        As LongPtr
#Else
    Private Declare Function ShellExecute _
        Lib "shell32.dll" Alias "ShellExecuteA" _
            (ByVal hwnd As Long, _
             ByVal lpOperation As String, _
             ByVal lpFile As String, _
             ByVal lpParameters As String, _
             ByVal lpDirectory As String, _
            ByVal nShowCmd As Long) _
        As Long
#End If
Private Const SW_HIDE = 0
Sub FilePrint(ByVal strFilePath As String)

    Dim retVal As Long
    
        retVal = ShellExecute(0, "Print", strFilePath, 0, 0, SW_HIDE)

        If retVal < 32 Then
           '// there are Error codes for this..left out
            MsgBox "An Error occured...could not print"
        End If

End Sub
Public Sub Print_All_PDF_Files_in_Folder()
    Dim folder As String
    Dim PDFfilename As String
    
    folder = "C:\Users\16468\Desktop\CONF\TAXES"    'CHANGE AS REQUIRED
    If Right(folder, 1) <> "\" Then folder = folder & "\"
       
    PDFfilename = Dir(folder & "*.pdf", vbNormal)
    While Len(PDFfilename) <> 0
        FilePrint folder & PDFfilename
        PDFfilename = Dir()  ' Get next matching file
    Wend
End Sub

原始代码在这里找到

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73315644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档