Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA automatic bookmark child levels leaving an open process

Status
Not open for further replies.

sweeptech

Technical User
Feb 25, 2006
1
US
Hello all

VBA6 IAC'd to AA6, under Win XP Pro

I've been using the core of this code (below) for quite a while now. It accesses an Excel spreadsheet with pages, levels, and bookmark names on it and appropriately bookmarks an open PDF via the jso object. Now, my code installs bookmarks via 'sendkeys' during a PDF building process (so that a listing of their names is unnecessary). But I do create a list (on a worksheet) of all the specified levels, in order. So I've used 'arrange bookmarks' of the code below, virtually verbatim, to take the existing bookmarks in the finished PDF and 'child-a-fy' them to the specified levels. And it works. But it leaves an open 'acrobat.exe' process open after AA6 closes down. Not a task, mind you, a process. The open process doesn't affect AA6 when I use it manually, after running my code, so it's not that noticiable... until I run my code again. Then it crashes. So I've had to '3 finger' AA6 prior to running my code everytime to clear this process. BTW, the line with '>>>>' appears to be the offending code. Now, recently I've brought in a 'process terminate' API to kill the process. And it works. But it's not very elegant. My VB Automation documentation says that alot of things will cause a hanging process: circular references, global variables, and such. And that problem code line looks circular to me, but, really, I'm stymied by this one. Anybody seen this before? Or maybe a more elegant solution to automatic bookmarking with 2 levels? I've got SDK's, but the bookmark root stuff is a bit cryptic to me.

Thanks
Dave

' ---------------------------------------------------------------------------
' Macros for automatic bookmark hierarchy creation from VBA via Javascript
' (C) Grunenthal GmbH, Stolberg / Germany
' Author: Jens Kammerath - Jens.Kammerath@grunenthal.de, kammera@t-online.de
' ---------------------------------------------------------------------------
' Acrobat (full version >= 5.0, not only reader) must be opened
' with PDF file to be processed in foreground window
' ---------------------------------------------------------------------------

Option Explicit

' ---------------------------------------------------------------------------
' MakeBookmarks - Creates Bookmarks on respective pages, no hierarchy so far
' ---------------------------------------------------------------------------
' Why not with JSObject?
' 1. Attaching bookmarks to pages much easier with Acrobat interface
' 2. Incorrect handling of international char's with bookmark.name assignment
' ---------------------------------------------------------------------------
Sub MakeBookmarks()
Dim i%
AppActivate "Adobe Acrobat", True
With Range("LstBookmarks")
For i = 1 To .Rows.Count
' Goto page
SendKeys "^n" & .Cells(i, 1) & "{Enter}", True
' Create bookmark
SendKeys "^b" & Trim(.Cells(i, 3)) & "{Enter}", True
Next i
End With
AppActivate "Microsoft Excel"
End Sub

' ---------------------------------------------------------------------------
' ArrangeBookmarks - Builds hierarchy
' ---------------------------------------------------------------------------
Sub ArrangeBoookmarks()
Dim gApp As Acrobat.CAcroApp
Dim gPDDoc As Acrobat.CAcroPDDoc
Dim gAVDoc As Acrobat.CAcroAVDoc
Dim jso As Object, bmRoot As Object, bm As Object
Dim children As Variant, children1 As Variant
Dim i%, nBM%, XNodes%(16), iLev%, BMText$, iPos%, XLev%(16)

Set gApp = CreateObject("AcroExch.App")
gApp.Show
Set gAVDoc = gApp.GetActiveDoc
Set gPDDoc = gAVDoc.GetPDDoc
' Javascript object
Set jso = gPDDoc.GetJSObject
' Root of bookmark tree
Set bmRoot = jso.bookmarkroot
' Children of root, all bookmarks on level 1 so far
>>>>children = bmRoot.children
nBM = UBound(children) - LBound(children) + 1
' temporary root for rearranging bookmarks
bmRoot.createchild "Temp Root", "", nBM
children = bmRoot.children
XNodes(0) = nBM
' XLev(i): counter number of children on level i
For i = 1 To 16
XLev(i) = 0
Next i
For i = LBound(children) To UBound(children) - 1
iLev = Range("LstBookmarks").Cells(i + 1, 2)
XLev(iLev) = XLev(iLev) + 1
children(XNodes(iLev)).insertchild children(i), XLev(iLev)
' XNodes(i): current parent bookmark on level i
XNodes(iLev + 1) = i
Next i
' Move bookmarks from temp to actual root
children1 = children(XNodes(0)).children
For i = LBound(children1) To UBound(children1)
bmRoot.insertchild children1(i), i + 1
Next i
' remove temp root
children(XNodes(0)).Remove
Set jso = Nothing
Set gPDDoc = Nothing
Set gAVDoc = Nothing
Set gApp = Nothing
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top