How to update a bookmark in a document based on a template using visual basic in visual studio 2012
I have created a word template using Word 2007. Based on the template I am able to open a new document from word and from a visual basic program using visual studio 2012. Everything works fine up to this point. In both cases I am able to enter data in the different fields (bookmarks) manually. Now I am trying to enter data from the same visual basic program that opened the new word document after getting values for the fields (bookmarks) from another section of the program. I have implemented many ways suggested on the web but have been unsuccessful. Could someone help me with entering data into the different fields (bookmarks) from my visual basic program. Thanks.
June 30th, 2015 12:10pm

I am using the following code that is claimed to work and is in production code

 if (doc.Bookmarks.Exists(name))
    {
       Word.Bookmark bm = doc.Bookmarks[name];
       Word.Range range = bm.Range.Duplicate;
       bm.Range.Text = text;                   // Bookmark is deleted, range is collapsed
       range.End = range.Start + text.Length;  // Reset range bounds
       doc.Bookmarks.Add(name, range);         // Replace bookmark
    }

The third line in the braces gives me error message in Catch as "The range cannot be deleted"

What am I doing wrong? Could someone show me code that works please

Free Windows Admin Tool Kit Click here and download it now
July 1st, 2015 3:22pm

Hi,

This is the forum to discuss questions and feedback for Microsoft Word,the issue is more related to Word coding/programing, I recommend you post the question to the MSDN forum for Word

http://social.msdn.microsoft.com/Forums/en-US/home?forum=worddev&filter=alltypes&sort=lastpostdesc

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

George Zhao
TechNet Community Support

July 2nd, 2015 1:27am

George,

As indicated in my previous reply, the OP had already posted the same question in MSDN...

As for your reference to installing the Configuration Analyzer Tool (OffCAT), I can't see what that's got to do with anything under discussion.

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 8:24pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics