Why does adding MsgBox change my results?

Re: Why does msgbox seem to change my subroutine?

From what Chris said I believe there's more to the NewBookMark command. When a bookmark is created it needs extra parameters and also needs to be saved. As Chris mentioned the msgbox causes the acroDoc to lose focus which in turn creates the bookmark with a name "Untitled".

If we think about bookmarks like a Tree data structure then we should be adding a bookmark to a node which will be the root for child nodes (i.e. for sub-headings) for example.

I will revisit this thread with some aircode later :)
 
It could be a timing issue. The MsgBox slows down the VBA code enough that Acrobat can keep up.
 
It doesn't seem like a timing issue. Even if I introduce Sleep commands or DoEvent commands, etc, it doesn't work.
 
It doesn't seem like a timing issue. Even if I introduce Sleep commands or DoEvent commands, etc, it doesn't work.

Doevents by itself will probably not pause long enough.

How long did you "sleep"?

Did you try using both the DoEvents followed by "Sleep" together?
 
Even if I spam multiple Sleep 1000's and DoEvents, it doesn't change anything.
 
I don't quite understand -- am I adding bookmarks wrong or using the wrong objects or both?

Great find though, thanks!
 
Follow what is in the code. It's in VB Script but easily adaptable. As I explained previously, it seems to create a bookmark you don't just call the menuitem NewBookmark, you create a node. Look at the structure of a bookmark, it's like a Tree data structure. A tree has nodes - parent nodes and child nodes.
 
Sure, but in this case I am just creating a bunch of Parents, right (each page is self-contained)? Is there something wrong with that?
 
Have you actually compared the code to what you have? The one by ReinhardF? It's nothing like yours. My comment on post #41 explains why your code wouldn't work without the msgbox based on what Chris mentioned.

You're calling the NewBookmark but not saving it.
 
That code worked! With some modifications, I changed it to:

If AVYourDoc.Open(filepath, title) Then

Set PDYourDoc = AVYourDoc.GetPDDoc()
Set JSO = PDYourDoc.GetJSObject
Set BMR = JSO.BookmarkRoot


'set bookmark title
For Each element In OfficeArray
AVYourDoc.FindText element, True, True, True
Set AVPage = AVYourDoc.GetAVPageView
BMR.createChild element, "this.pageNum=" & AVPage.GetPageNum, i
i = i + 1
Next element

End If


Thanks a lot, VBAInet!
 
You're welcome. Glad you got it working :)

Just a thought, instead of using i, it could be that element has an index method. Try replacing i with element.index see if it works.

Code:
BMR.createChild element, "this.pageNum=" & AVPage.GetPageNum, [B]element.index[/B]
 
Did not work unfortunately -- I assume the number at the end of the line refers to bookmark order (if I replace it with 0, for instance, it inserts everything in reverse. If I put it as 1, the order seems quite screwed. An increasing counter seems to do the trick)
 
I was just wondering if there is an index method of an element in an array in vba. I've just tested it in a different way as well and no it doesn't.

Good job! :)
 
Is there a way to keep the bookmark pane opened whenever anyone opens the pdf?

I can do AVYourDoc.SetViewMode (3) in the code to make it show as I am adding, but how do I get it to stay that way when I actually open the pdf?

I am basically trying to do File->Properties->Initial View -> Navigation Tab -> Bookmarks Panel and Page in VBA. Possible?
 
Last edited:
Not sure. You would need to look at the reference or SDK manual for that. I guess that would also involve using the PDDoc object to open the pdf and then perform perform the following operations you listed. Thinking about it, there must be a MenuItem for performing that operation.
 
Doevents by itself will probably not pause long enough.

How long did you "sleep"?

Did you try using both the DoEvents followed by "Sleep" together?

I did not know that. I always thought that DoEvents would allow all of the outstanding events to be completed before the processing continued.
 
I did not know that. I always thought that DoEvents would allow all of the outstanding events to be completed before the processing continued.
DoEvents (in the background) just gives more priority to the preceding operations.
 

Users who are viewing this thread

Back
Top Bottom