Accessing bookmarks by name is only possible by browsing the bookmark names. WrdBookmark returns a handle to a bookmark by taking its name as argument. WrdInsertBookmark, WrdDeleteBookmark inserts/deletes a bookmark in a Word document. WrdGotoBookmark allows to place the cursor on the bookmark and WrdUpdateBookmark replaces the content within the range of the bookmark in a Word document with the given text.

WrdBookmark(name, wrd = DescToolsOptions("lastWord"))

WrdInsertBookmark(name, wrd = DescToolsOptions("lastWord"))
WrdDeleteBookmark(name, wrd = DescToolsOptions("lastWord"))

WrdGoto(name, what = wdConst$wdGoToBookmark, wrd = DescToolsOptions("lastWord"))

WrdUpdateBookmark(name, text, what = wdConst$wdGoToBookmark,
                  wrd = DescToolsOptions("lastWord"))

Arguments

name

the name of the bookmark.

text

the text of the bookmark.

what

a word constant, defining the type of object to be used to place the cursor.

wrd

the pointer to a word instance. Can be a new one, created by GetNewWrd() or an existing one, created by GetCurrWrd(). Default is the last created pointer stored in DescToolsOptions("lastWord").

Details

Bookmarks are useful to build structured documents, which can be updated later.

Author

Andri Signorell <andri@signorell.net>

Examples

if (FALSE)  # we can't get this through the CRAN test - run it with copy/paste to console
wrd <- GetNewWrd()
WrdText("a)\n\n\nb)", fontname=WrdGetFont()$name, fontsize=WrdGetFont()$size)
#> Error in WrdText("a)\n\n\nb)", fontname = WrdGetFont()$name, fontsize = WrdGetFont()$size): could not find function "WrdText"
WrdInsertBookmark("chap_b")
#> Error in wrdBookmarks$Add(name): attempt to apply non-function
WrdText("\n\n\nc)\n\n\n", fontname=WrdGetFont()$name, fontsize=WrdGetFont()$size)
#> Error in WrdText("\n\n\nc)\n\n\n", fontname = WrdGetFont()$name, fontsize = WrdGetFont()$size): could not find function "WrdText"

WrdGoto("chap_b")
#> Error in wrdBookmarks$exists(name): attempt to apply non-function
WrdUpdateBookmark("chap_b", "Goto chapter B and set text")
#> Error in wrdSel$GoTo(What = what, Name = name): attempt to apply non-function

WrdInsertBookmark("mybookmark")
#> Error in wrdBookmarks$Add(name): attempt to apply non-function
ToWrd("A longer text\n\n\n")
#> Error in wrd[["Selection"]]$InsertAfter(paste(x, collapse = "\n")): attempt to apply non-function

# Now returning the bookmark
bm <- WrdBookmark("mybookmark")
#> Error in wbms$count(): attempt to apply non-function

# get the automatically created name of the bookmark
bm$name()
#> Error in eval(expr, envir, enclos): object 'bm' not found