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; }
|