none
Run MSWord 2007 project from another project RRS feed

  • Question

  • Hi everybody. I'm developing a windows application within a solution, and in order to generate reports, I added another project of type visual C# > office > 2007 > word 2007 document to the same solution. This project is debugged well and works when it's selected as start-up project, but I need to run it somewhere within my application. I referenced the .dll file of the word project at my application project, but it's not possible to declare an object of this namespace and class because of partial keyword used at the definition. Is there anyway to run my word project at run-time and send data to it? Any help would be appreciated greatly. 
    Monday, October 13, 2014 7:44 AM

Answers

All replies

  • Hello,

    It looks like you develop a Word document-level add-in. In that case you can use common techniques for communicating between separate processes - .Net Remoting, named pipes and etc.

    If you decide to develop an application-level add-in, you can communicate to them directly. See Calling Code in Application-Level Add-ins from Other Office Solutions for more information.

    Monday, October 13, 2014 8:34 AM
  • Hi again, and thanks to your answer. I reviewed the topic. It seems that Application level add-ins are available at MS.Office 2013 and MS.Office 2010. Are they available at Office 2007 too?

    I've developed a class and it works correct, but slow a bit (see code below). That was why I tried to add an independent word2007 project to my solution. 

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls;
    using Telerik.WinControls.UI;
    using System.Linq;
    using System.Xml.Linq;
    using System.Reflection;
    using Microsoft.Office.Tools.Word;
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    using Office = Microsoft.Office.Core;
    using Word = Microsoft.Office.Interop.Word;
    using System.IO;
    
    namespace RailwaySpotting.Classes
    {
        class MSWordReporting : IDisposable
        {
    
            public Word._Application oWord;
            public Word._Document oDoc;
            DataTable SectionsList;
    
            public MSWordReporting()
            {
                
            }
    
            public void Dispose()
            {
                
            }
    
            private void GenerateNewWordDocument()
            {
                
                object oMissing = System.Reflection.Missing.Value;
                object oEndOfDoc = "\\endofdoc";
                
                oWord = new Word.Application();
                oWord.Visible = true;
                oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    
                oDoc.PageSetup.PaperSize = Word.WdPaperSize.wdPaperA4;
                oDoc.PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait;
                oDoc.PageSetup.HeaderDistance = 18;
                oDoc.PageSetup.FooterDistance = 16;
                oDoc.PageSetup.BottomMargin = 85;
                oDoc.PageSetup.LeftMargin = 56;
                oDoc.PageSetup.RightMargin = 56;
                oDoc.PageSetup.TopMargin = 72;
               
            }
    
        }
    }

    Monday, October 13, 2014 8:52 AM
  • Yes, they are supported since Office 2000 if I remember correctly.

    Solutions that were created by using Visual Studio 2013, Visual Studio 2013 or Visual Studio 2010 can run in Office 2013, Office 2010, or the 2007 Microsoft Office system. However, the solution can use only those features and APIs that are available in all three versions of Office. See Running Solutions in Different Versions of Microsoft Office .

    Monday, October 13, 2014 9:02 AM