我目前正在写一个宏,它从excel索引中提取数字。然后查找具有相同名称的PDF文件,并将它们合并为一个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, 0, 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我希望这是足够的信息。我真的不想发布整个代码,因为它太长了。感谢您的努力。
发布于 2020-08-25 21:28:13
请添加此行
objCAcroPDDocSource.Open (thisarray(i))之后
For i = LBound(thisarray) + 1 To UBound(thisarray)您未打开Source文件,因此没有要合并的内容...
https://stackoverflow.com/questions/63578917
复制相似问题