Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Get the Word Template in VSTO Addin of a new Document

13.11.2018 (👁161)

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;

}