What are the limitations for bookmark names in Microsoft Word?

user105393 picture user105393 · May 12, 2009 · Viewed 11.8k times · Source

I need to bookmark parts of a document from the name of paragraphs but the name of a paragraph is not always a valid name for a bookmark name. I have not found on Google or MSDN an exhaustive list of limitations for bookmark names.

What special characters are forbidden?

The only thing I found is that the length must not exceed 40 characters.

Answer

Tomalak picture Tomalak · May 12, 2009

If you are familiar with regular expressions, I would say it is

^(?!\d)\w{1,40}$

Where \w refers to the range of Unicode word characters, which also contain the underscore and the digits from 0-9.

In plain English: The bookmark name must...

  • be between 1 and 40 characters long
  • consist of any combination of Unicode letters, digits, underscores
  • not start with a digit
  • not contain any kind of white space or punctuation

As stated in the comments, bookmark names beginning with an underscore are treated as hidden. They will not appear in the regular user interface, but they can be used from VBA code. It it is not possible to create bookmarks that begin with an underscore via the regular user interface, but you can do it through VBA code with Bookmarks.Add().