Hi need help with trying to loop a building block - it won't insert. Building block is saved in Building Blocks.dotx for the moment as: Custom Autotext Category Receipts Title Receipt Error Highlighted: Set objBB = objTemplate.BuildingBlockTypes(wdTypeCustomAutoText) _ *** Error Requested Member of Collection Does not Exist .Categories("Receipts").BuildingBlocks("Receipt") Sub TestMe1() Dim intReceipt As Integer Dim i As Integer Dim objTemplate As Template Dim objBB As BuildingBlock intReceipt = InputBox("How many Receipts do you need?", "Number of Receipts") Do While i < intReceipt 'Insert the Building Block Entry ' Set the template to store building block Set objTemplate = ActiveDocument.AttachedTemplate ' Access the building block through the type and category Set objBB = objTemplate.BuildingBlockTypes(wdTypeCustomAutoText) _ *** Error Requested Member of Collection Does not Exist .Categories("Receipts").BuildingBlocks("Receipt") ' Insert building block in document replacing any selected text. objBB.Insert Selection.Range ' ActiveDocument.AttachedTemplate.AutoTextEntries("Receipt").Insert _ ' Where:=Selection.Range, RichText:=True ' 'Make sure the cursor is at the end of the Receipt ' Selection.EndKey Unit:=wdStory 'Increment the counter i = i 1 Loop End Sub
I think you are overcomplicating things - try Dim intReceipt As Integer Dim i As Integer Dim objTemplate As Template Dim objBB As BuildingBlock intReceipt = InputBox("How many Receipts do you need?", "Number of Receipts") Do While i < intReceipt Set objTemplate = ActiveDocument.AttachedTemplate Set objBB = objTemplate.BuildingBlockEntries("Receipt") objBB.Insert Selection.Range i = i 1 Loop or use Set objBB = objTemplate.BuildingBlockTypes(wdTypeAutoText) _ .Categories("Receipts").BuildingBlocks("Receipt") -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "JosephSmith" wrote in message news:eLMirRRIJHA.508@TK2MSFTNGP05.phx.gbl... Hi need help with trying to loop a building block - it won't insert. Building block is saved in Building Blocks.dotx for the moment as: Custom Autotext Category Receipts Title Receipt Error Highlighted: Set objBB = objTemplate.BuildingBlockTypes(wdTypeCustomAutoText) _ *** Error Requested Member of Collection Does not Exist .Categories("Receipts").BuildingBlocks("Receipt") Sub TestMe1() Dim intReceipt As Integer Dim i As Integer Dim objTemplate As Template Dim objBB As BuildingBlock intReceipt = InputBox("How many Receipts do you need?", "Number of Receipts") Do While i < intReceipt 'Insert the Building Block Entry ' Set the template to store building block Set objTemplate = ActiveDocument.AttachedTemplate ' Access the building block through the type and category Set objBB = objTemplate.BuildingBlockTypes(wdTypeCustomAutoText) _ *** Error Requested Member of Collection Does not Exist .Categories("Receipts").BuildingBlocks("Receipt") ' Insert building block in document replacing any selected text. objBB.Insert Selection.Range ' ActiveDocument.AttachedTemplate.AutoTextEntries("Receipt").Insert _ ' Where:=Selection.Range, RichText:=True ' 'Make sure the cursor is at the end of the Receipt ' Selection.EndKey Unit:=wdStory 'Increment the counter i = i 1 Loop End Sub