Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Word Template in VSTO Addin

 

How to determine the template of a Word document when launching a C # code in debug in Visual Studio

 

Solution:

You can only use the associated template with .get_AttachedTemplate (); determine.

Unfortunately, you can only open documents from the Word application and open templates from the Internet when the debug is started.

I could not open a new document1 from my own template.

So here's the code, which still worked.

 

Solution code

Determine the actual template of a new document in Word

C #, intercom addin

var varTemplate = Globals.ThisAddIn.Application.ActiveDocument.get_AttachedTemplate();

            if (varTemplate != null)

            {

                Word.Template template = (Word.Template)varTemplate;

                sWordPath =template.Path;

            }

 

 

 

 

string sFilename = Settings1.Default.Excel_Filename;

if (sFilename.IndexOf(":") < 0)

{

    string sWordPath = Globals.ThisAddIn.Application.ActiveDocument.Path;

    if(sWordPath=="")

    {

        try

        {

            var varTemplate = Globals.ThisAddIn.Application.ActiveDocument.get_AttachedTemplate();

            if (varTemplate != null)

            {

                Word.Template template = (Word.Template)varTemplate;

                sWordPath =template.Path;

            }

        }

        catch (Exception )

        {

 

            throw;

        }

        

    }

    sFilename = sWordPath + "\\" + sFilename;

}

 

 

Mobile
»
Code: Word Addin with photos resize and paste in Word
»
How to Get the Word Template or a New Word Document in VSTO Addin
»
Word Addin: Adds customer data from Excel file to Word file
»
Saving Settings in Office Addin VSTO
»
Word: Loop through all the words in a Word document
»
Load data grid in C #. Example here in WinForms, VSTO add-in

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de