我有列中的数字列表,我想将它们合并到一个前缀相同的文件名中。
例如:12345678_1.pdf 12345678_2.pdf
我希望它保存到特定文件夹。
你能帮我解决VBA代码或cmd代码吗?我能搞清楚
答案 0 :(得分:0)
主要程序可能是:
Sub MergeAll()
Dim i As Long
For i = 1 To 9999 Step 2
If Cells(i, 1).Value = "" Then Exit For
MergePDF "E:\0\A\MergePdf\", Cells(i, 1).Value, Cells(i + 1, 1).Value, Left(Cells(i, 1).Value, Len(Cells(i, 1).Value) - 5) & ".pdf"
Next
End Sub
以及合并它的被调用程序:
Sub MergePDF(PathF, strExportFile1, strExportFile2, strExportFileX As String)
' Reference Necessary: Adobe Acrobat xx Type Library
'Relies on the Adobe Acrobat 6.0 Type Library
Dim objCAcroPDDocDestination As Acrobat.CAcroPDDoc
Dim objCAcroPDDocSource As Acrobat.CAcroPDDoc
'Initialize the 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 (PathF & strExportFile1)
objCAcroPDDocSource.Open (PathF & strExportFile2)
If objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
Debug.Print "Documents Merged!"
Else
Debug.Print "Document NOT Merged!"
End If
objCAcroPDDocSource.Close
objCAcroPDDocDestination.Save 1, PathF & strExportFileX
objCAcroPDDocDestination.Close
Set objCAcroPDDocSource = Nothing
Set objCAcroPDDocDestination = Nothing
End Sub
代码需要安装&引用:
Adobe Acrobat xx Type Library