Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

Inserting a Building Block Quick Part

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mjfour - 05 Feb 2008 00:58 GMT
I'm at my wits end, I hope someone can help. I an trying to figure out how to
insert a specfic quick part I have created at a bookmark in my word 2007
document through VBA.  I need code that will allow me to loop the entry
several times as needed, one time I will need to insert the quick part 3
times and one time 5 times. Now the quick part are saved in the document
template not the "normal.doc" tempate.
Doug Robbins - Word MVP - 05 Feb 2008 02:37 GMT
Take a look at the Working with Building Blocks item in the Word Developer
Reference that you can access through the Help facility in the Visual Basic
Editor.

It contains the following on inserting a Building Block Entry:

Inserting a Building Block into a Document

After you have access to a building block, use the Insert method of the
BuildingBlock object to insert it into a document. The following example
expands the previous code sample by adding a line for inserting the building
into the active document at the Insertion Point (or for replacing the
selected text, if text is selected).

Note

When you insert a building block by using the Ribbon, Word automatically
determines certain things about the building block, such as where to insert
it; however, when you insert a buildng block through the object model, none
of this built-in intelligence automatically happens. For example, when you
insert a header building block by using the Ribbon, Word automatically
determines to replace the existing header. When inserting the same header
building block by using the object model, you need to explicitly specify
where to place the building block text.

Sub InsertExistingBuildingBlock()

   Dim objTemplate As Template
   Dim objBB As BuildingBlock

   ' Set the template to store the building block
   Set objTemplate = ActiveDocument.AttachedTemplate

   ' Access the building block through the type and category
   Set objBB = objTemplate.BuildingBlockTypes(wdTypeCustomHeaders) _
       .Categories("Book Titles").BuildingBlocks("Title")

   ' Insert the building block into the document replacing any selected
text.
   objBB.Insert Selection.Range

End Sub

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> I'm at my wits end, I hope someone can help. I an trying to figure out how
> to
[quoted text clipped - 3 lines]
> times and one time 5 times. Now the quick part are saved in the document
> template not the "normal.doc" tempate.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.