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

Java, C++, C#, Delphi, ??? - Using the UNO bridges

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

Postby cluelessDev114 » Tue Dec 20, 2011 6:06 pm

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   Expand viewCollapse view
        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   Expand viewCollapse view
BookmarkField.setString("")

leaves the 'Dear' in the document i have also tried
Code: Select all   Expand viewCollapse view
FoundBookmark.dispose()

and
Code: Select all   Expand viewCollapse view
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
cluelessDev114
 
Posts: 2
Joined: Tue Dec 20, 2011 5:52 pm

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

Postby FJCC » Wed Dec 21, 2011 12:10 am

This OOoBasic code deletes the text encompassed by the bookmark and the bookmark itself.
Code: Select all   Expand viewCollapse view
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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7748
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

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

Postby cluelessDev114 » Wed Dec 21, 2011 2:01 pm

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
cluelessDev114
 
Posts: 2
Joined: Tue Dec 20, 2011 5:52 pm

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

Postby FJCC » Wed Dec 21, 2011 3:43 pm

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   Expand viewCollapse view
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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7748
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA


Return to External Programs

Who is online

Users browsing this forum: No registered users and 2 guests