Avatar of William C Johnson
William C Johnson
Flag for United States of America asked on

Why won't this building block macro run?

The following macro fails to run.  It was created using Word 2007 macro recorder.  I can perform these steps manually but when using the macro, it fails at the ActiveDocument statement.  Why?  See attached document.

Sub Test()
'
' Test Macro
'
    Selection.HomeKey Unit:=wdStory
    ActiveDocument.AttachedTemplate.BuildingBlockEntries("Meeting Cancelled"). _
        Insert Where:=Selection.Range, RichText:=True
End Sub
Test.docx
Microsoft WordOffice ProductivityLotus IBM

Avatar of undefined
Last Comment
William C Johnson

8/22/2022 - Mon
GrahamSkan

If you get an error message, please tell us what the message is.

When I run your macro I get the message:
Run-time error '5941':
The requested member of the collection does not exist.

This is not surprising, because I don't have a Building Block Entry of that name. Have you?
Richie_Simonetti

If you are run the macro in the same document that you are trying to, please change "ActiveDocument" to ThisDocument" object.
Sometimes, if you don't have "focus" on desired document, ActiveDocument fails.
Cheers
William C Johnson

ASKER
This macro continues to give me an error whether I use the ThisDocument or ActiveDocument object.  I see the building block entry in the list and can insert it manually but it won't work as recorded by the macro recorder.  What gives?  See attached document.
Test.dotx
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
GrahamSkan

We can't reliably diagnose the error because we don't have the template that is Attached to your document. Also you haven't told us what the error message is.
ASKER CERTIFIED SOLUTION
GrahamSkan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
William C Johnson

ASKER
For some reason the building block template got disconnected.  I have repaired the file and it works as designed.  Thank you all for your insight.

Bill