[Solved] How To Delete a Bookmark in VB.NET?

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
cluelessDev114
Posts: 2
Joined: Tue Dec 20, 2011 5:52 pm

[Solved] How To Delete a Bookmark in VB.NET?

Post by cluelessDev114 »

Hello All,
I am trying to create a document from a template and delete a specific bookmark. The code i use to get the boookmark is

Code: Select all

        Dim BookmarksSupplier As XBookmarksSupplier = CType(Document, XBookmarksSupplier)
        Dim FoundBookmark As XTextContent = CType(BookmarksSupplier.getBookmarks.getByName(Bookmark).Value, XTextContent)
        Dim BookmarkField As XTextRange = FoundBookmark.getAnchor()
The bookmark i am deleting inserts the word 'Dear' before the bookmark text, using

Code: Select all

BookmarkField.setString("")

leaves the 'Dear' in the document i have also tried

Code: Select all

FoundBookmark.dispose()
and

Code: Select all

Dim Writer As XTextDocument = CType(Document, XTextDocument)
Writer.getText.removeTextContent(FoundBookmark)
both to no effect.

Thanks for your help
Last edited by cluelessDev114 on Wed Dec 21, 2011 2:01 pm, edited 1 time in total.
OpenOffice 3.3 on Windows 7
FJCC
Moderator
Posts: 9624
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How To Delete a Bookmark in VB.NET?

Post by FJCC »

This OOoBasic code deletes the text encompassed by the bookmark and the bookmark itself.

Code: Select all

oBookmarks = ThisComponent.Bookmarks
oMark = oBookmarks.getByName("Mark1")
oMark.Anchor.String = ""
oMark.dispose()
I notice the you say that the word "Dear" is before the bookmark. Does the word get highlighted if you jump to the bookmark? If not, then you cannot manipulate the bookmark anchor to delete it.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
cluelessDev114
Posts: 2
Joined: Tue Dec 20, 2011 5:52 pm

Re: How To Delete a Bookmark in VB.NET?

Post by cluelessDev114 »

Thanks for your help.

I think your right, its not actually part of the bookmark, just text before the bookmark which is why this is not working
OpenOffice 3.3 on Windows 7
FJCC
Moderator
Posts: 9624
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: [SOLVED]How To Delete a Bookmark in VB.NET?

Post by FJCC »

If the word is consistently placed relative to the bookmark, it could still be manipulated by using a text cursor. For example

Code: Select all

oBookmarks = ThisComponent.Bookmarks
oMark = oBookmarks.getByName("Mark1")
oText = ThisComponent.Text
oCurs = oText.createTextCursor
oCurs.gotoRange(oMark.Anchor, False)
oCurs.gotoPreviousWord(True)
oCurs.String = ""
I don't know that will work in your case, but I hope it gives you an idea of how a cursor may be used.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply