Ask Your Question
0

Macro code to access bookmarks in another document [closed]

asked 2016-09-28 23:19:13 +0200

Mr Spock gravatar image

updated 2016-09-28 23:34:36 +0200

mark_t gravatar image

From my main document "CreateBookmarks" my macro code creates a new document based on a template "Bookmarks" that contains several bookmarks. I am having difficulties referring to these bookmarks.

Here is my test code contained in "CreateBookmarks":

Sub CreateBookmarkDoc

    Dim sURL as String
    Const sPathName = "F:\Users\ifsian\Documents\OpenOffice\Templates\Bookmarks.ott"

    sURL = ConvertToURL(sPathName)
    StarDesktop.loadComponentFromURL(sURL,0,"_default",Array())

    msgbox "Bookmark Count: " & ThisComponent.getBookmarks().getcount()

End Sub

When executed in the original document, ThisComponent.getBookmarks().getcount() returns 0. If the above code is copied into a module under MyMacros and Dialogs and executed it works. A new document is created and the count of bookmarks in the document just created returned. I am guessing ThisComponent.getBookmarks().getcount() is counting bookmarks in the original document rather than the document just created even though this document has focus.

My question is:

What is the correct syntax to access bookmarks in another document?

Edited format of code block. mark_t

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Mr Spock
close date 2016-10-01 13:37:21.072909

2 Answers

Sort by » oldest newest most voted
0

answered 2016-09-28 23:29:15 +0200

mark_t gravatar image

updated 2016-09-28 23:32:12 +0200

Instead of using ThisComponent use the object returned by loadComponentFromURL.

Example:- (Note I have not tested this but it should be OK)

Edit to correct format of the code

Sub CreateBookmarkDoc 

    Dim sURL as String 
    Const sPathName = "F:\Users\ifsian\Documents\OpenOffice\Templates\Bookmarks.ott"
    Dim oDoc As Object

    sURL = ConvertToURL(sPathName)
    oDoc = StarDesktop.loadComponentFromURL(sURL,0,"_default",Array())

    msgbox "Bookmark Count: " & oDoc.getBookmarks().getcount()

End Sub
edit flag offensive delete link more
0

answered 2016-09-28 23:50:09 +0200

Mr Spock gravatar image

Thank you mark_t that works.

I am still trying to understand the LO object model. I have been reading Andrew Pitonyak's book and recording macros to attempt to gain a better understanding of LO macros but there are times when my old addled brain fails me!

edit flag offensive delete link more

Comments

PS: What is the protocol for marking a question as [closed]?

Mr Spock gravatar imageMr Spock ( 2016-09-28 23:55:47 +0200 )edit

If you could check the grey tickmark next to the answer that best answers your question. You might also find a close option below your question, but I'm not sure if that requires minimum ammount of Karma to be enabled.

mark_t gravatar imagemark_t ( 2016-09-29 00:03:05 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-28 23:19:13 +0200

Seen: 60 times

Last updated: Sep 28 '16