Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 408835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:43:50+00:00 2026-05-12T17:43:50+00:00

A little back story : I have small application that will use Word to

  • 0

A little back story: I have small application that will use Word to generate a Outlook signature based on a Word template and data from the company active directory. It works wonderful on computers with Office 2007, since I used “Microsoft Word 12.0 Object Library” when I coded it on my own computer.

There are quite a few computers on the network with Office 2003 though, and on those computers “Microsoft Word 12.0 Object Library” is missing, resulting in exceptions left and right.

My question is: How do I detect which version of Office is installed and thus which version of the “Microsoft Word Object Library” is available, and subsequently load it. I am quite sure that the functionality I am using are in both the “Microsoft Word 12.0 Object Library” and the “Microsoft Word 11.0 Object Library”.

In case anybody is interested, here is my current code used to generate the signature:

class Signature
{
    public Dictionary<string, string> TemplateMappings { get; set;}
    public string SignatureTemplateFileName { get; set; }
    public string SignatureName { get; set;}
    public bool UseSignatureWithNewMessages { get; set; }
    public bool UseSignatureInReplyMessages { get; set; }

    public Signature()
    {
        UseSignatureWithNewMessages = true;
        UseSignatureInReplyMessages = true;
        TemplateMappings = new Dictionary<string, string>();
    }

    public void Create()
    {
        if(string.IsNullOrEmpty(SignatureTemplateFileName) || !File.Exists(SignatureTemplateFileName))
        {
            throw new InvalidOperationException("SignatureTemplateFileName is null or the file do not exists");
        }

        if(string.IsNullOrEmpty(SignatureName))
        {
            throw new InvalidOperationException("No SignatureName specified");
        }

        object nullObject = System.Reflection.Missing.Value;
        object signatureTemplate = SignatureTemplateFileName;

        // open word doc
        var word = new ApplicationClass();
        var doc = word.Documents.Add(ref signatureTemplate, ref nullObject, ref nullObject, ref nullObject);

        // search/replace user info
        object wdReplaceAll = WdReplace.wdReplaceAll;
        var find = word.Selection.Find;
        foreach (var pair in TemplateMappings)
        {
            find.Text = pair.Key;
            find.Forward = true;
            find.MatchCase = true;
            find.MatchWholeWord = true;
            find.Replacement.Text = pair.Value;
            find.Execute(ref nullObject /* FindText */,
                         ref nullObject /* MatchCase*/,
                         ref nullObject /* MatchWholeWord*/,
                         ref nullObject /* MatchWildcards*/,
                         ref nullObject /* MatchSoundsLike*/,
                         ref nullObject /* MatchAllWordForms*/,
                         ref nullObject /* Forward*/,
                         ref nullObject /* Wrap*/,
                         ref nullObject /* Format*/,
                         ref nullObject /* ReplaceWith*/,
                         ref wdReplaceAll /* Replace*/,
                         ref nullObject /* MatchKashida*/,
                         ref nullObject /* MatchDiacritics*/,
                         ref nullObject /* MatchAlefHamza*/,
                         ref nullObject /* MatchControl */);
        }

        // Add signature to outlook
        var signatureRange = doc.Range(ref nullObject, ref nullObject);
        word.EmailOptions.EmailSignature.EmailSignatureEntries.Add(SignatureName, signatureRange);

        // set new signature as default for news messages and replies
        if (UseSignatureWithNewMessages)
            word.EmailOptions.EmailSignature.NewMessageSignature = SignatureName;
        if (UseSignatureInReplyMessages)
            word.EmailOptions.EmailSignature.ReplyMessageSignature = SignatureName;

        // close and clean up
        doc.Saved = true;
        doc.Close(ref nullObject, ref nullObject, ref nullObject);
        word.Quit(ref nullObject, ref nullObject, ref nullObject);
    }
}

Any help will be much appreciated. Input on the code above is also welcome; I do not have any experience coding against Office Interop library, so I am sure there are things I can do differently.

Best regards, Egil.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:43:50+00:00Added an answer on May 12, 2026 at 5:43 pm

    OK found what I was looking for.

    MS Office For Net abstracts away the headaches of the underlying Office interop assembly versions. Perhaps you can use it directly in your project, else study it’s implementation to understand how to address this issue. The folks working on that project are probably a great resource to ask interop questions as well..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I little while back I posted this question . I have updated that question
Back story i have a table that stores cached times, and currently has about
a little back story: I am working on a file that got to be
Just need a little bit of Javascript to warn people that press the back
I have a little class called Stuff that I want to store things in.
I have a nice little app on the app store that does pretty well
Let's say I have a javascript method that takes a little to long to
I am currently designing an iOS 5 iPhone app that will use a .NET
I have an asp.net application c# that uses session state to store a variable
I have an input file that I want to sort based on timestamp which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.