none
How to read WOrd template name? RRS feed

  • Question

  • Hi,

    I am trying to read currently active word document's template name, but an exception is occuring.

    Code :

    string templatename = ((Microsoft.Office.Core.DocumentProperties)(wordApp.ActiveDocument.BuiltInDocumentProperties)) [Word.WdBuiltInProperty.wdPropertyAuthor].Value.ToString();

    Exception:

    Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Core.DocumentProperties'. This operation failed because the QueryInterface call on the COM component for the interface

    Could someone help me out what is the wrong in above code?

    Thanks,

    P


    • Edited by Prasad 2000 Friday, August 26, 2011 1:18 PM edited code
    • Moved by CoolDadTx Friday, August 26, 2011 1:28 PM Office related (From:Visual C# General)
    Friday, August 26, 2011 1:17 PM

Answers

  • wordApp.ActiveDocument.get_AttachedTemplate.FullName;
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Prasad 2000 Wednesday, August 31, 2011 6:29 AM
    Friday, August 26, 2011 1:55 PM
    Moderator
  • Thanks Cindy.

    But this helped me to get the template name:

    Word.Template template = (Word.Template)targetDoc.get_AttachedTemplate();
    
    string templateName = template.Name;
    

     

    • Marked as answer by Prasad 2000 Wednesday, August 31, 2011 6:29 AM
    Saturday, August 27, 2011 7:22 AM

All replies

  • wordApp.ActiveDocument.get_AttachedTemplate.FullName;
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Prasad 2000 Wednesday, August 31, 2011 6:29 AM
    Friday, August 26, 2011 1:55 PM
    Moderator
  • Thanks Cindy.

    But this helped me to get the template name:

    Word.Template template = (Word.Template)targetDoc.get_AttachedTemplate();
    
    string templateName = template.Name;
    

     

    • Marked as answer by Prasad 2000 Wednesday, August 31, 2011 6:29 AM
    Saturday, August 27, 2011 7:22 AM