5 Replies Latest reply: Sep 17, 2009 5:17 AM by in2thecode RSS

    Add bookmarks to pdf file using Excel VBA

    in2thecode Community Member

      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.