PDA

View Full Version : Save building block to dotx file in Document Building Blocks folder ... possible?



Hezakiya
02-14-2013, 10:43 AM
Happy Valentine's Day!
This code loops through all of the bookmarks in my document and saves each one as a building block in the attached template. I need to save it to the “EC Building Blocks.dotx” file in my Document Building Blocks folder.


Sub LoopAllBookmarksToMakeBBsOfBiosInOwnParagraph()
Dim oBM As Bookmark
Dim lngCount As Long
Dim r As Range
Dim objTemplate As Template
Dim objBB As BuildingBlock
Dim objName As String

For lngCount = 1 To ActiveDocument.Bookmarks.Count
Set oBM = ActiveDocument.Bookmarks(lngCount)
Set r = ActiveDocument.Bookmarks(oBM.Name).Range
objName = r.Paragraphs.First.Range

Set objTemplate = ActiveDocument.AttachedTemplate
Set objBB = objTemplate.BuildingBlockEntries.Add(Name:=objName, _
Type:=wdTypeCustom4, _
Category:="General", _
Range:=r, _
InsertOptions:=wdInsertParagraph)
Next lngCount
End Sub


Is there a way to automatically save my building blocks into the “EC Building Blocks.dotx” file in my Document Building Blocks folder? Instead of to the attached template?

Thanks very much!

gmaxey
02-14-2013, 08:14 PM
Load the template. Then instead of Setting objTemplate = ActiveDocument.AttachedTemplate, Loop through the templates collection:

For Each objTemplate In Templates
If objTemplate.Name = "EC Builging Blocks.dotx" Then
Exit For
End Inf
Next

Hezakiya
02-15-2013, 06:35 AM
You're amazing! Thank you so much; I appreciate the very speedy reply.