Hi everyone. I am currently merging multiple PDFs together and was hoping for a solution to merge together with bookmarks.
This is what I have currently:
I found this (Create PDF bookmarks while combinding files with VBA in Excel) so tried to change the code to this:
My rubbish hack job of trying to slip in the code didn't kill the code. It's still merging - but not making the bookmarks. Where did I go wrong? Also how do I modify the Bookmark name so it's the name of the file I inserted?
Much thanks!
This is what I have currently:
VBA Code:
For n = 1 To UBound(PDFfiles)
objCAcroPDDocDestination.Open Path & PDFfiles(n, 1)
For i = 2 To 10
If PDFfiles(n, i) <> "" Then
objCAcroPDDocSource.Open Path & PDFfiles(n, i)
If Not objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
MsgBox "Error merging" & vbCrLf & PDFfiles(n, 1) & vbCrLf & "and" & vbCrLf & PDFfiles(n, i)
End If
objCAcroPDDocSource.Close
Else
End If
Next i
I found this (Create PDF bookmarks while combinding files with VBA in Excel) so tried to change the code to this:
Code:
For n = 1 To UBound(PDFfiles)
objCAcroPDDocDestination.Open Path & PDFfiles(n, 1)
For i = 2 To 10
Dim insertSuccess As Boolean
Dim x As Long, p As Long
Dim JSO As Object, BookMarkRoot As Object
p = objCAcroPDDocDestination.GetNumPages
If PDFfiles(n, i) <> "" Then
objCAcroPDDocSource.Open Path & PDFfiles(n, i)
If Not objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
MsgBox "Error merging" & vbCrLf & PDFfiles(n, 1) & vbCrLf & "and" & vbCrLf & PDFfiles(n, i)
End If
insertSuccess = objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0)
If insertSuccess Then
x = x + 1
Set JSO = objCAcroPDDocDestination.GetJSObject
Set BookMarkRoot = JSO.BookMarkRoot
BookMarkRoot.createchild "Bookmark " & x & " Page " & p + 1, "this.pageNum=" & p, n
End If
objCAcroPDDocSource.Close
Else
End If
Next i
My rubbish hack job of trying to slip in the code didn't kill the code. It's still merging - but not making the bookmarks. Where did I go wrong? Also how do I modify the Bookmark name so it's the name of the file I inserted?
Much thanks!