初始化PDF reDirect ProFinding以合并两个文件时出错

时间:2018-05-05 12:47:13

标签: vba pdf merge access-vba

我发现这段代码应该找到两个匹配的pdf文件名,并将它们合并为1个pdf文件,总是以相同的顺序。文件1然后文件2.

代码根据文件名的第一部分,在AnotherWord 2014.pdf之前或SomeWord.pdf之前匹配文件名。

  • 示例文档名称1:John Doe SomeWord.pdf
  • 示例文档名称2:John Doe AnotherWord 2014.pdf

我使用 PDF reDirect Pro v2.5.2(免费软件)以及对该程序的引用。

我遇到的问题是该行

Dim oPDF As New PDF_reDirect_v25002.Batch_RC_AXD

这给了我错误:

  

未定义的用户定义类型

我该如何解决这个问题?

这是整个代码:

    Private Sub Knop0_Click()

'Only works with PDF reDirect Pro v2.5.2
'And needs to have a reference to PDF_reDirect_v2500 and PDF reDirect Pro Remote Control
Dim fs As Object
Dim fld As Object
Dim fld2 As Object
Dim objFile As Object
Dim objFile2 As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim oPDF As New PDF_reDirect_v25002.Batch_RC_AXD
Dim TempBool As Boolean
Dim Files_to_Merge(1) As String
Dim ObjFileName() As String
Dim CellNameValue() As String
Dim ofn As String
Dim cnv As String
Dim i As Integer

Set fld = fs.GetFolder("C:\pdf")
Set fld2 = fs.GetFolder("C:\pdf\merged")
i = 1

For Each objFile In fld.files
For Each objFile2 In fld.files
    CellNameValue() = Split(objFile.Name, " SomeWord.pdf")
    cnv = CellNameValue(0)
    ObjFileName() = Split(objFile2.Name, " AnotherWord 2014.pdf")
    ofn = ObjFileName(0)
    Files_to_Merge(1) = fld & "\" & ofn & " AnotherWord 2014.pdf"
    Files_to_Merge(0) = fld & "\" & cnv & " SomeWord.pdf"
    If StrComp(ofn, cnv) = 0 Then
    With oPDF

        TempBool = .Utility_Merge_PDF_Files(fld2 & "\" & ofn & " AnotherWord 2014.pdf", Files_to_Merge) 'The file merges here unless it generates an error and goes to If Not TempBool Then...

        If Not TempBool Then
            MsgBox "An Error Occured: etc."
        Else
            'Optional
        End If
    End With
    End If
    i = i + 1
    Next objFile2
     i = i + 1
    Next objFile
    Set oPDF = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

正如我在评论中所说,假设您的试用专业版仍然允许使用此功能,这应该可行。

您只需确保使用已在系统上注册的对象的正确版本。

你可以删除行Dim oPDF As New PDF_reDirect_v25002.Batch_RC_AXD并从头开始重新输入 - 不是复制/粘贴吗?当您开始键入PDF_Re

时,该工具的对象是否显示在Intellisense中

如果它是什么,请输入找到PDF_reDirect_v2500的对象 - 然后输入.并开始输入Batch以填写最后一部分。您必须使用当前版本的对象引用。

编译代码并查看是否超过该行