none
Custom Building blocks RRS feed

  • Question

  • I want to insert some content from my own Custom Building Blocks template, without turning this template into an attached template. The reason is that the document is already attached to some other template. Is this possible in MS Word 2007 - 2013? I cann't do this piece in OOXML, it should be accomplished using Word Object Model API.

    Thanks,

    Michael


    Wednesday, November 20, 2013 8:10 PM

Answers

  • Hi Michael

    If the template is loaded as an Add-in template, yes, you should be able to do this using the Word object model, no problem.

    You should be able to see this in the Word UI by going to Developer/Templates; in the bottom half of the dialog box, if your template is not listed, click "Add", browse to the template and "Open" it; it should appear in the list. Then go to the Building Blocks interface (Insert/Quick Parts/Building Blocks Organizer, for example) and you should see the entries from your template in the list.

    The process in the Word OM is pretty much that same. You manage your template using Application.AddIns. Make sure its BB entries are accessible by calling the Application.Templates.LoadBuildingBlocks method.

    Note: If you place your templates in Word's Startup folder then you won't need to work with the AddIns collection.

    Note: Best practise is to loop the AddIns collection, checking whether the templates is present. If not, you use AddIns.Add method, which is the equivalent of clicking the "Add" button. If it is present, set the Installed property to True to make sure it's loaded.

    The AddIn item's Name property will be the file name of the template. In order to get the TEMPLATE object you need if you want to access the BB programmatically from the template, you use the Name as an Index value for the Templates collection. (It's not possible to cast an AddIn object to a Template object.)


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, November 21, 2013 4:10 PM
    Moderator

All replies

  • Hi Michael,

    According to your description, you want to insert some content of a custom building block without inserting it into the document. Please correct me if I have any misunderstandings.

    >> The reason is that the document is already attached to some other template. Is this possible in MS Word 2007 - 2013? <<

    I don’t think it is possible even using the Word Object Model.

    In this case, I suggest you to save the content as a separated building block and insert this building block as content only; if so, it will not affect existing templates.

    Hope it helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, November 21, 2013 8:38 AM
    Moderator
  • Hi Michael

    If the template is loaded as an Add-in template, yes, you should be able to do this using the Word object model, no problem.

    You should be able to see this in the Word UI by going to Developer/Templates; in the bottom half of the dialog box, if your template is not listed, click "Add", browse to the template and "Open" it; it should appear in the list. Then go to the Building Blocks interface (Insert/Quick Parts/Building Blocks Organizer, for example) and you should see the entries from your template in the list.

    The process in the Word OM is pretty much that same. You manage your template using Application.AddIns. Make sure its BB entries are accessible by calling the Application.Templates.LoadBuildingBlocks method.

    Note: If you place your templates in Word's Startup folder then you won't need to work with the AddIns collection.

    Note: Best practise is to loop the AddIns collection, checking whether the templates is present. If not, you use AddIns.Add method, which is the equivalent of clicking the "Add" button. If it is present, set the Installed property to True to make sure it's loaded.

    The AddIn item's Name property will be the file name of the template. In order to get the TEMPLATE object you need if you want to access the BB programmatically from the template, you use the Name as an Index value for the Templates collection. (It's not possible to cast an AddIn object to a Template object.)


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, November 21, 2013 4:10 PM
    Moderator
  • Sorry Jeffrey, I probably should've been more precise in describing the issue.
    Basically I'm trying to insert a watermark from my own Building blocks dotx file.

    The main problem is, that in our solultion(VSTO addin) all the documents are based on another attached template.

    So, I coded something like this:

    1 Save the attached template info
    2 Attach custom building block template to the document.
    3 Insert a building block.
    4 Restore the previously saved attached template.

    This seems to work, but I haven't tested it completely yet.

    Thanks,

    Michael
    Sunday, November 24, 2013 9:09 PM
  • Thank you Cindy, but shipping addin template isn't an option for us. Looks like I got the code to work (as described in reply to Jeffry's post). All is left is to code the "Remove Watermark" feature.

    Regards,

    Michael

    Monday, November 25, 2013 6:16 PM