locked
run-time error Macro 5941 the requested member of the collection does not exist RRS feed

  • Question

  • Hi everyone,

    can someone help? Every time I record a macro and assign it to a key when I open a new document and use the short-cut to run the macro I get the above message. 

    This part of the Marco is highlighted 

      Application.Templates( _
            "C:\Users\Open\AppData\Roaming\Microsoft\Document Building Blocks\1033\15\Built-In Building Blocks.dotx" _
            ).BuildingBlockEntries("Plain Number 1").Insert Where:=Selection.Range, _
            RichText:=True 

    What am I doing wrong? I have windows 8.1 and I'm using Microsoft 2013 it says. 

    Thanks in advance

    Friday, January 17, 2014 10:58 AM

Answers

  • Insert the following statement before the highlighted statement and save your macro:

    Application.Templates.LoadBuildingBlocks

    Peter Jamieson


    Friday, January 17, 2014 8:35 PM

All replies

  • Hello Georgiamaib,

    First of all, I'd recommend breaking the long chain of calls to separate lines of code (independent calls). Let's start from the beginning.

    The Templates property of the Application class returns an instance of the corresponding class from the Word object model. You can iterate via all members and find the required one, for example:

    Count = 1 
    For Each aTemplate In Templates 
     MsgBox aTemplate.Name & " is template number " & Count 
     Count = Count + 1 
    Next aTemplate
    

    The Template class provides the BuildingBlockEntriesproperty which returns a  BuildingBlockEntries collection that represents the collection of building block entries in a template. You may iterate over all items in the collection and find the required one. After you've found the one you may use the Insert method of the BuildingBlock class.

    Also after you've found the required Template you may use OpenAsDocumentmethod which allows to open the specified template as a document and return a Document object.

    Friday, January 17, 2014 12:03 PM
  • Insert the following statement before the highlighted statement and save your macro:

    Application.Templates.LoadBuildingBlocks

    Peter Jamieson


    Friday, January 17, 2014 8:35 PM