Macro error 5941

D

DianneZ

Hello!
I am trying to write a macro to insert a header with one of the standard
building block entry headers in the quick parts list.

When I try, I get the error messge 5941. From reading other posts I can tell
it cannot find the building blocks template - this is confusing since they
are the default entries and I can use them while not in a macro - so it would
seem word knows where the building blocks template is. hmm .... help would
be so appreciated.
Here is the code:
Sub insert_header2()
'
' insert_header2 Macro
' dianne recorded
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
-----HANGS UP ON THE LINE BELOW------
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Alphabet").Insert _
Where:=Selection.Range, RichText:=True
Selection.TypeText Text:="Axolotl header"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
 
T

Tony Jollans

Building Block Templates are opened on first use in the UI. In VBA you must
ensure they are open before using them - to do this, use:

Templates.LoadBuildingBlocks
 

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