Error Inserting CustomAutotextBuildingBlock

J

Jules

Hi, I still cannot get this to insert the customautotext "Receipt" at all! Any ideas on a solution please.

Sub ATeInsert1()
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 the template to store the building block
Set objTemplate = ActiveDocument.AttachedTemplate

' Access the building block through the type and category
Set objBB = objTemplate.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Receipts").BuildingBlocks("Receipt")


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

i = i + 1
Loop

End Sub
 
G

Graham Mayor

You already asked this in an earlier post yet you are still using the same
code :(

Change the line
Set objBB =
objTemplate.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Receipts").BuildingBlocks("Receipt")
to
Set objBB =
objTemplate.BuildingBlockTypes(wdTypeAutoText).Categories("Receipts").BuildingBlocks("Receipt")


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


Hi, I still cannot get this to insert the customautotext "Receipt" at all!
Any ideas on a solution please.
 
J

Jules

Yes true,
I did alter the code and I changed it back again. It does not work for me.
 
G

Graham Mayor

If it doesn't work for you then the probability is that you have saved the
autotext entry in some location other than the document template's Autotext
gallery Receipts category with a name other than Receipt.

If the Building Blocks entry is saved as Autotext, in the Receipts category
of that group and in the template the document was created from then it
should work as posted.

By default Building Blocks are saved in BuildingBlocks.dotx in the Quick
Parts gallery under the General category.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jules

For the moment it resides in default buildingblocks.dotx and is saved
intentionally to CustomAutotext Receipts Receipt.

It shows in BuildingBlocks and it shows in CustomAutotext button on Ribbon -
it just does not insert.

If I use your line it just highlights it and End Debug ...

Not to worry...
 
G

Graham Mayor

In that case you would need to include the path to the active Building
Blocks.dotx file eg

Set objTemplate = Templates("C:\Documents and
Settings\<UserName>\Application Data\Microsoft\Document Building
Blocks\1033\Building Blocks.dotx")
Set objBB =
objTemplate.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Receipts").BuildingBlocks("Receipt")
objBB.Insert Selection.Range


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jules

Graham, I realise BB resides there - does that mean it doesn't think of
itself as a global - it rebuilds automatically?

I was just doing that now - putting a path.

Thank you.
 
G

Graham Mayor

It doesn't appear to in this context. Personally I would move the autotext
entry to the normal template for my own use or the document template for
distribution. You can do this easily enough from the Building Blocks
organizer. Then your original code should work.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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