Adobe Acrobat Pro DC无法响应VBA命令

问题描述

我目前正在编写一个宏,该宏采用Excel索引中的数字。然后找到同名的PDF文件,并将它们合并为1个PDF文件。

但是我无法使结合了文件的部分正常工作,而我找不到正确设置引用的原因。

这是我遇到的问题。

Dim objCAcroPDDocDestination As Acrobat.CAcroPDDoc
Dim objCAcroPDDocSource As Acrobat.CAcroPDDoc
Dim i As Integer
Dim iFailed As Integer
Dim strSaveAs As String
Dim MergePDFs As Boolean


strSaveAs = GetNewFolder & "\" & TxtNewFileName.Text
 
On Error GoTo NoAcrobat:
'Initialize the Acrobat objects
Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
 
'Open Destination,all other documents will be added to this and saved with
'a New Filename
objCAcroPDDocDestination.Open (thisarray(LBound(thisarray))) 'open the first file
 
'Open each subsequent PDF that you want to add to the original
  'Open the source document that will be added to the destination
    For i = LBound(thisarray) + 1 To UBound(thisarray)
        
       If objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1,objCAcroPDDocSource,objCAcroPDDocSource.GetNumPages,0) Then
          MergePDFs = True
        Else
          'failed to merge one of the PDFs
          iFailed = iFailed + 1
        End If
        objCAcroPDDocSource.Close
    Next i
objCAcroPDDocDestination.Save 1,strSaveAs 'Save it as a new name
objCAcroPDDocDestination.Close
Set objCAcroPDDocSource = Nothing
Set objCAcroPDDocDestination = Nothing
 
NoAcrobat:
If iFailed <> 0 Then
    MergePDFs = False
End If
On Error GoTo 0

我希望这是足够的信息。我真的不想发布整个代码,因为它很长。 谢谢您的努力。

解决方法

请添加此行

objCAcroPDDocSource.Open (thisarray(i))

之后

For i = LBound(thisarray) + 1 To UBound(thisarray)

您没有打开Source文件,因此无法合并...

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...