Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > How to find where Building Blocks have been inserted in a Word 2007 document
 

How to find where Building Blocks have been inserted in a Word 2007 document

(cross posted to Office Developer forum as well)

It recently came to our attention that when a Building Block has been inserted into a document (and I mean an end-user document, not a template) that there is one character position taken by some sort of anchor for the BB.  If your cursor is before that position, you see only the "output" of the BB.  However, if you press the right-arrow, the BB is activated.  The content of that one character position takes one "character" (referring to a Characters collection or to Range.Move operation) but has a .Text value of an empty string.  BTW, if you delete that Character range, the BB functionality goes away, but the contents remain (similar to when you do a Field.Unlink.)

We would like to find the locations within a document where such items occur, but we haven't been able to figure out whether there's a any place that they are referenced in the Object Model, such as collection that they belong to, or a navigation method (such as Selection.Next..) which can be used to access them.
Fletcher James President Levit & James, Inc. www.levitjames.com
Fletcher James  Friday, October 16, 2009 6:25 PM

Hello Fletcher,

Welcome to MSDN forums!

As my understanding, you are going to find out the location of the Building Blocks in a Word document, right?

As you mentioned in your post:
"there is one character position taken by some sort of anchor for the BB. If your cursor is before that position, you see only the "output" of the BB. However, if you press the right-arrow, the BB is activated."

Do you mean the blue frame-like border? If you move your mouse into the range the border appears, if your mouse if out of the range it disappears.
Actually, this is not a Building Block, this is a Content Control, a Building Block is a combination of multiple controls, the Content Control is one of them. And we could access the Content Control via Document.ContentControls collection.

For more Information about ContentControls please refer to this link:
http://msdn.microsoft.com/en-us/library/bb256559.aspx

For the Location valueyou want, we could retrieve the ContentControl.Range property, and Range.Start will return the location of first character in this range.

If you have any further questions, please feel free to ask.

Thanks.

Tim Li
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tim Li  19 hours 21 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• OFFSET Function
• VSTO 2010 release date
• Outlook add-ins: Runtime errors on load after installing VS 2008 sp1I
• get foldername from outlook to vb.net
• VSTO Cypress : Where's the CTP?
• problem with Replacement in word document using C#
• How to detect if vstor 2005 se is installed?
• Opinion about a ActionsPane in VSTO
• Copy Page From "a.docx" to "b.docx" - With images, graphics ...
• Which "Event Handler-adding" code is more appropriate for my application add-in?