Copy link to clipboard
Copied
Good morning -
I have, through internet searches, created an Excel macro that prints numerous workbooks to pdf, combines them into one file and prints that file. I have been searching for the last piece, which is adding bookmarks, but have not had any luck getting any of it to work. The following is the code that I am using to add the bookmarks -
Dim avdoc, pddoc, app As Object
Dim stFile As String
Dim btitle As Boolean
Dim PDBookmark As CAcroPDBookmark
stFile = "D:\Test\Test.pdf"
Set app = CreateObject("AcroExch.app")
Set avdoc = CreateObject("AcroExch.AVDoc")
Set pddoc = CreateObject("AcroExch.PDDoc")
pddoc.Open stFile
Set avdoc = pddoc.OpenAVDoc(stFile)
Set PDBookmark = CreateObject("AcroExch.PDBookmark", "")
app.MenuItemExecute ("NewBookmark")
btitle = PDBookmark.SetTitle("Test Bookmark")
This code does insert a bookmark on the first page of the document. The bookmark title displays as Untitled instead of Test Bookmark as the code states. Can someone answer the following questions -
1. Why is the code not changing the bookmark from Untitled to Test Bookmark, and
2. How would I nodify the above code to go to a certain page then enter the bookmark.
All help is greatly appreciated. Thanks in advance for your time.
Hi,
these discussion reminds me to an excellent VBA example from Jens Kammerath,
which also answer your next question = how to set up bookmarks as tree.
Also save some work and testing :-)).
You can download from:
http://www.ReFob.de/downloads/Acrobat/AcroJsBookmarksVBA.zip
HTH, Reinhard
Copy link to clipboard
Copied
1. You first have to get it, then you can set it.
something like(untested):
app.MenuItemExecute ("NewBookmark")
PDBookmark.GetByTitle PDDoc, "Untitled"
btitle = PDBookmark.SetTitle("Test Bookmark")
2. Before you create the bookmark you have to go to to the page - like you would do it manual.
HTH, Reinhard
Copy link to clipboard
Copied
Good morning Reinhard -
Thanks you very much for the help. I implemented as follows:
1. app.MenuItemExecute ("NewBookmark")
btitle = PDBookmark.GetByTitle(pddoc, "Untitled")
btitle = PDBookmark.SetTitle("Total Accessories / Hardgoods")
I added the "btitle =" due to it erroring out. However, when I step through the code and get to that line, I get the "Excel has encountered an error and needs to close" error. Is there a reference that I'm missing that you know of?
2. I was able to find the code to get to a specific page number and it is working great.
Thanks again for all of your assistance.
Copy link to clipboard
Copied
You have to make sure btitle is not null after getting the reference to the bookmark, and then call SetTitle on the bookmark objects, not on the PDBookmark class.
Copy link to clipboard
Copied
Hi Patrick -
Thanks for the information. I'm not exactly sure how to implement that. Would you have an example?
Copy link to clipboard
Copied
Oooh,
forgot it.
with:
app.MenuItemExecute ("NewBookmark")
you set Acrobat into edit mode (you may test it manual).
So after that you have to use sendkey with Enter or ESC to finish edit mode.
Then you can get and set the title.
If you are at this state you may think about to use only sendkey for all 3 commands.
SendKeys "^b" & "Text" & "{Enter}", True
best regards, Reinhard
Copy link to clipboard
Copied
Thanks for the quick response. I see what you mean about the edit mode. I replaced the app.MenuItemExecute ("NewBookmark") with SendKeys "^b" & "Text" & "{Enter}", True but it does not do anything now. It appears to run the line of code just does not seem to activate the menu. Any ideas?
Copy link to clipboard
Copied
Hi,
these discussion reminds me to an excellent VBA example from Jens Kammerath,
which also answer your next question = how to set up bookmarks as tree.
Also save some work and testing :-)).
You can download from:
http://www.ReFob.de/downloads/Acrobat/AcroJsBookmarksVBA.zip
HTH, Reinhard
Copy link to clipboard
Copied
Thanks for the information. Using that example I determined why the sendkeys wasn't working. It appears that I must show the app as well as use appactivate before the sendkeys. All is working now. Thank you very much for all of your assistance.
Copy link to clipboard
Copied
Hi could you please share the code? I am working on similar automation to add bookmarks in pdf.
Copy link to clipboard
Copied
Hello ReinhardF,
A few years later, but still people are searching for ways to make bookmarks in e tree like fasion using VBA.
Unfortunally the file you mentioned, http://www.ReFob.de/downloads/Acrobat/AcroJsBookmarksVBA.zip, does no longer exist.
Is there a way that i can retrieve this file?
Regards Jos