【问题标题】:How can I print list pdf file with name them in column excel?如何打印列表 pdf 文件并在 excel 列中命名它们?
【发布时间】:2020-10-07 08:55:08
【问题描述】:

我想在 excel 的 1 列中打印名称为 pdf 的列表文件。

我不想按住按钮 Ctrl 并在 excel 列中一一找到它的名称并选择那些文件。因为可能有很多文件。一个一个查找需要很多时间。

以上图为例。

什么软件可以支持我做到这一点?或者我必须做任何事情来解决这个问题???

感谢您阅读我的帖子!!!

【问题讨论】:

  • 我找到了this。如果可行,您可以定义包含地址的范围,使用 For-Next 循环选择所述范围的每个单元格,然后运行正确编辑的子例程。
  • 我尝试使用他们的代码只输入一个特定的文件名,而不是使用 For-Next 来获取多个文件名。但是它报告了这样的错误。你能帮我看看这个错误吗?
  • 这是我的代码: If Err.Number > 0 Then MsgBox Err.Number & ": " & Err.Description PrintPDF = False Else PrintPDF = True End If On Error GoTo 0 End Function Sub PrintSpecificPDF( ) '打开指定的 pdf 并使用默认打印机打印 '注意它使用默认的 PDF 程序并保持打开状态 Dim strPth As String, strFile As String strPth = "D:\PDF\" strFile = "B01611.pdf" If Not PrintPDF(0, strPth & strFile) Then MsgBox "Printing failed" End If End Sub

标签: excel printing export-to-excel software-design


【解决方案1】:

这应该可行:

Public 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
 
Public Function PrintPDF(xlHwnd As Long, FileName As String) As Boolean
    Dim X As Long
    
    On Error Resume Next
    X = ShellExecute(xlHwnd, "Print", FileName, 0&, 0&, 3)
    
    If Err.Number > 0 Then
        MsgBox Err.Number & ": " & Err.Description
        PrintPDF = False
    Else
        PrintPDF = True
    End If
    On Error GoTo 0
End Function
 
Sub PrintSpecificPDF()
    'opens the specified pdf and prints it using the default printer
    'note that it uses the default PDF program and leaves it open
    
    Dim strPth As String, strFile As String
    Dim rngList As Range, rngTarget As Range
    
    
    Set rngList = Range(Range("B2"), Range("B1").End(xlDown))
    strPth = "D:\PDF\"
    
    For Each rngTarget In rngList
        
        strFile = rngTarget.Value & ".pdf"
         
        If Not PrintPDF(0, strPth & strFile) Then
            MsgBox "Printing failed"
        End If
        
    Next
    
End Sub

我采用了这个code 并根据您的情况对其进行了轻微修改。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多