Hi experts.. below is my issue
I have a pdf file and am trying to insert bookmarks in that pdf file based on the cell text and page numbers mentioned in excel. In excel i have mentioned the page number to be bookmarked and the bookmark title content. When i execute this i receive an end of statement error. Please help to resolve this.
*NOTE: Am not trying to convert the excel into pdf with bookmarks. I need to insert the bookmarks that i specify in excel into an existing pdf file.
Below is the code am using.
I have a pdf file and am trying to insert bookmarks in that pdf file based on the cell text and page numbers mentioned in excel. In excel i have mentioned the page number to be bookmarked and the bookmark title content. When i execute this i receive an end of statement error. Please help to resolve this.
*NOTE: Am not trying to convert the excel into pdf with bookmarks. I need to insert the bookmarks that i specify in excel into an existing pdf file.
Below is the code am using.
VBA Code:
Sub Add Bookmark()
Dim AcroApp As Acrobat.CAcroApp
Dim PDoc As Acrobat.CAcroPDDoc
Set AcroApp = CreateObject(“AcroExch.App”)
Set PDoc = CreateObject(“AcroExch.PDDoc”)
PDoc.Open (ThisWorkbook.Worksheets(“Add Bookmark”).Cells(2, 1))
Set jso = PDoc.GetJSObject
jso.BookmarkRoot.Remove
Set BMR = jso.BookmarkRoot
a = 0
For i = 2 To ThisWorkbook.Sheets(“Add Bookmark”).Range(“B” & Rows.Count).End(xlUp).Row
pg = ThisWorkbook.Sheets(“Add Bookmark”).Cells(i, 3) – 1
bm = ThisWorkbook.Sheets(“Add Bookmark”).Cells(i, 2)
af = ThisWorkbook.Sheets(“Add Bookmark”).Cells(i, 4)
bf = ThisWorkbook.Sheets(“Add Bookmark”).Cells(i, 5)
cf = ThisWorkbook.Sheets(“Add Bookmark”).Cells(i, 6)
df = ThisWorkbook.Sheets(“Add Bookmark”).Cells(i, 7)
If pg > “” And bm > “” And (af > “” Or bf > “” Or cf > “” Or df > “”) Then
If af = “Y” Then
BMR.createChild bm, “this.pageNum = ” & pg, a
BMA = BMR.Children
Set oBMA = BMA(a)
a = a + 1
b = 0
c = 0
d = 0
End If
If bf = “Y” Then
oBMA.createChild bm, “this.pageNum = ” & pg, b
BMB = oBMA.Children
Set oBMB = BMB(b)
b = b + 1
c = 0
d = 0
End If
If cf = “Y” Then
oBMB.createChild bm, “this.pageNum = ” & pg, c
BMC = oBMB.Children
Set oBMC = BMC(c)
c = c + 1
d = 0
End If
If df = “Y” Then
oBMC.createChild bm, “this.pageNum = ” & pg, d
d = d + 1
End If
Else
MsgBox “Row: ” & i & “, title or page number or bookmark level missing!”
Exit Sub
End If
Next i
n = PDoc.Save(PDSaveFull, ThisWorkbook.Worksheets(“Add Bookmark”).Cells(2,1))
PDoc.Close
AcroApp.Exit
Set AcroApp = Nothing
Set PDoc = Nothing
Set ADoc = Nothing
MsgBox “Done!”
End Sub
Last edited by a moderator: