scripting the insertion of a quick block entry (word 2007)

A

abc

Hi All,

I have entered an entry in my bulding blocks as follows:

Name: myentry
Gallery: QuickParts
Category: General
Template: Building Blocks.dotx
Behavior: Insert Content.

If I open the Building Blocks Organize I can insert the entry in my
document with no problems.


Now I would like to script this, so that i can insert "myentry" using a
key sequence. So I looked up some example code and came up with this script:


--------------------------------------------
Sub MyBldBlock()



Dim objTemplate As Template
Dim objBB As BuildingBlock



Set objTemplate =
ActiveDocument.AttachedTemplate.BuildingBlockEntries("building blocks.dotx")




Set objBB =
objTemplate.BuildingBlockTypes(wdTypeQuickParts).Categories("General").BuildingBlocks("myentry")
objBB.Insert Selection.Range

End Sub

---------------------------------------------------------------------------

But it does not work. It looks like I am not linking correctly the the
Building blocks.dotx template...

Any suggestion?

Thanks a lot for your help!
 
G

Greg Maxey

Something like this:

Sub ScratchMacro()
Dim oTmp As Template
'Ensure BB template is loaded.
Templates.LoadBuildingBlocks
For Each oTmp In Templates
If oTmp.Name = "Building Blocks.dotx" Then Exit For
Next oTmp
oTmp.BuildingBlockEntries("myentry").Insert Selection.Range
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top