none
start another Word template RRS feed

  • Question

  • I am building an add-in application in VSTO for MS Word 2016.

    In my project I have multiple Word templates (dotx). I am searching for the code to create a Word document based on one of the templates in the solution.

    Hope you can help me.

    Thanks in advance.

    Jim de la Combe

    jimdelacombe@outlook.com


    Jim de la Combe freelance VBA developer

    Thursday, May 24, 2018 2:16 PM

All replies

  • Hello Jim,

    Documents.Add(Template,NewTemplate,DocumentType,Visible)

    Specific the first Template argument to create a new document based on specific document.

    Here is the example.

            Dim wdApp As Microsoft.Office.Interop.Word.Application = Globals.ThisAddIn.Application
            Dim dotxPath As String = "C:\Users\admin\Desktop\TestFolder\Test.dotx"
            wdApp.Documents.Add(dotxPath)

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 25, 2018 2:14 AM
  • Hi Terry,

    first of all thanks for your quick reply.

    What I see in your example code is the hard-coded location of the template ("C:\Users\admin\Desktop\TestFolder\Test.dotx"). 

    But my question was how to open a template that is already in my VSTO project (VSS solution)?

    That is what I am looking for.

    Thanks in advance

    Jim


    Jim de la Combe freelance VBA developer

    Friday, May 25, 2018 6:10 PM
  • Hello VBAjim,

    It seems that you want to get relative path string instead of absolute path string in C#.

    Please try to check if below threads helpful.

    How to get relative path of a file in visual studio?

    How to get relative path from absolute path

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 28, 2018 7:09 AM