Question

I am trying to translate a previously created Word 2007 ribbon set (8 tabs, about 150 buttons and 10 checkboxes) from VB done in VS2005 to C# in VS2010. The issue I'm having is that I'm unable to set the control for the buttons to open a new document using a template with macros enabled. I have a confirmed file path for each template and I've used a VB-C# translator, but for some reason it's not working properly. Here is what I have as my method for loading the template(s) so far:

   private void _LoadTemplate(string templateName)
    {
        string templatePath1 = "//Macro - Development";
        string templatePath2 = "//Macro - Development/Templates No Longer Updated";
        if(File.Exists(templatePath1 + templateName))
        {
            Document doc = Application.Documents.Add(Template = templatePath1 + templateName);
        }
        else if (File.Exists(templatePath2 + templateName))
        {
            Document doc = Application.Documents.Add(Template = templatePath2 + templateName);
        }
        else
        {
            MsgBox = "Template does not exist.";
        }
Was it helpful?

Solution

There are a few main options:

  • Use Office Automation COM libraries - works great, but has a few conditions:
    • You need to license Office (or at least Word) for the computer's that the code's running on (if Office isn't already installed)
    • You cannot use it in a server-side, desktop-less environment (e.g. from within an ASP.NET application). This is not a supported scenario.
  • Use a third-party library like Aspose.
    • The catch is it's horrdenously expensive.
  • Use a SaaS service like Saaspose
    • It's reasonably priced: $15 a month, however it isn't as flexible as a local library like Aspose, and requires a reliable Internet connection.
  • Use the OOXML libraries directly, but you say you don't want to dabble with XML directly.

Office 2007 and Office 2010 Word document files are essentially identical, as is the programming model and API changes between them - I think the only difference that matters is that Office 2010's UI looks better than 2007.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top