locked
Inserting building blocks through VBA RRS feed

  • Question

  • I am using Word 2010.  I have created a building block that includes a bulleted list.  If I manually insert the building block, the formatting (bullets) inserts properly. 

    I want to automate the insertion of certain building blocks.  So I create a bookmark, and apply some VBA code.  When doing this, only the text from the building block inserts, the bullets are removed.  Part of the code is listed below:

    .Bookmarks("bookmarkname").Range _
        .InsertAfter ActiveDocument.AttachedTemplate.BuildingBlockEntries("buildingblockname")

    Any ideas as to why I am loosing the bullets and only the text is inserted?

    Thanks in Advance

    Ken


    Kenneth Clebak
    Friday, October 1, 2010 7:23 PM

Answers

  • I think you need code like this instead:
     
    ActiveDocument.AttachedTemplate _
    .BuildingBlockEntries("buildingblockname") _
    .Insert _
    Where:=ActiveDocument.Bookmarks("bm_name").Range, _
    RichText:=True
     
    Stefan Blom
    Microsoft Word MVP


    "Kenneth Clebak" wrote in message news:6c37406b-1770-4fe5-a14a-d456c3669620@communitybridge.codeplex.com...

    I am using Word 2010.  I have created a building block that includes a bulleted list.  If I manually insert the building block, the formatting (bullets) inserts properly.

    I want to automate the insertion of certain building blocks.  So I create a bookmark, and apply some VBA code.  When doing this, only the text from the building block inserts, the bullets are removed.  Part of the code is listed below:

    .Bookmarks("bookmarkname").Range _
        .InsertAfter ActiveDocument.AttachedTemplate.BuildingBlockEntries("buildingblockname")

    Any ideas as to why I am loosing the bullets and only the text is inserted?

    Thanks in Advance

    Ken


    Kenneth Clebak

    Stefan Blom, Microsoft Word MVP
    • Marked as answer by Jennifer Zhan Monday, October 4, 2010 3:57 AM
    Friday, October 1, 2010 7:41 PM

All replies

  • I think you need code like this instead:
     
    ActiveDocument.AttachedTemplate _
    .BuildingBlockEntries("buildingblockname") _
    .Insert _
    Where:=ActiveDocument.Bookmarks("bm_name").Range, _
    RichText:=True
     
    Stefan Blom
    Microsoft Word MVP


    "Kenneth Clebak" wrote in message news:6c37406b-1770-4fe5-a14a-d456c3669620@communitybridge.codeplex.com...

    I am using Word 2010.  I have created a building block that includes a bulleted list.  If I manually insert the building block, the formatting (bullets) inserts properly.

    I want to automate the insertion of certain building blocks.  So I create a bookmark, and apply some VBA code.  When doing this, only the text from the building block inserts, the bullets are removed.  Part of the code is listed below:

    .Bookmarks("bookmarkname").Range _
        .InsertAfter ActiveDocument.AttachedTemplate.BuildingBlockEntries("buildingblockname")

    Any ideas as to why I am loosing the bullets and only the text is inserted?

    Thanks in Advance

    Ken


    Kenneth Clebak

    Stefan Blom, Microsoft Word MVP
    • Marked as answer by Jennifer Zhan Monday, October 4, 2010 3:57 AM
    Friday, October 1, 2010 7:41 PM
  • Stefan:

    Thank you very much for the feedback, you code was exactly what I needed and it solved my problem.

    Thank You

    Kenneth Clebak


    Kenneth Clebak
    Friday, October 8, 2010 1:06 PM
  • I’m glad I could help!

    "Kenneth Clebak" wrote in message news:433baaec-3bbf-4172-a4e1-7eb8b0b92b1c@communitybridge.codeplex.com...

    Stefan:

    Thank you very much for the feedback, you code was exactly what I needed and it solved my problem.

    Thank You

    Kenneth Clebak


    Kenneth Clebak

    Stefan Blom, Microsoft Word MVP
    Friday, October 8, 2010 6:12 PM
  • What about if I want to insert a table (created as buildBlock) in the current position of my activeDocument?
    Wednesday, January 22, 2014 10:57 AM
  • What about if I want to insert a table (created as buildBlock) in the current position of my activeDocument?

    You can use Selection.Range instead of ActiveDocument.Bookmarks("bm_name").Range. Note that the code above assumes that you saved the Building Block in the template attached to the current document.


    Stefan Blom, Microsoft Word MVP

    Wednesday, January 22, 2014 2:08 PM